WPF and canvas overlay

Posted by user200851 on Stack Overflow See other posts from Stack Overflow or by user200851
Published on 2009-11-02T12:22:32Z Indexed on 2010/05/27 13:01 UTC
Read the original article Hit count: 761

Filed under:
|
|
|

I have a grid which represents some data, and i need a canvas to overlay on top of it to layout some lines. The canvas is inside it's own usercontrol

The problem is that the canvas and it's contents should autoresize when the grid resizes width and height.

I added the canvas inside a viewbox, but it didn't do the trick. When the grid resizes, the canvas doesn't. The purpose of the canvas is to overlay a ruler-like functionality on top of the grid.

I cannot use a style on the grid to replace the canvas, because the grid is showing different information than the canvas does. Think of it as chart, in which there are bar columns of different sizes (in my case the grid) and the days are lines in an overlay (just as a Gannt Chart)

My code:

taxCanvas = new TimeAxis();
Grid.SetRowSpan(taxCanvas, GRightMain.RowDefinitions.Count);
Grid.SetColumnSpan(taxCanvas, GRightMain.ColumnDefinitions.Count);
Grid.SetColumn(taxCanvas, 0);    Grid.SetRow(taxCanvas, 0); 
Grid.SetZIndex(taxCanvas, -1);
taxCanvas.Height = GRight.ActualHeight;
taxCanvas.Width = GRight.ActualWidth;
GRightMain.Children.Add(taxCanvas);

TimeAxis is my canvas usercontrol, GRightMain is a grid which holds both my canvas and the grid with the content (Gright) in the same row and column.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about grid