I have the following layout:
The Rectangle
s are placed using a Grid
. On top of that, I want to add more "fluid" stuff, like Path
s and lines that would be located dynamically.
For instance:
Rectangle
s, are stretched from one Rectangle
's mid-point to the mid-point of the one below itRectangle
, and go to the mid-point of the left Rectange
below it.So the question is: the Rectangle
s match Grid
behavior, other stuff, like the lines, match Canvas
behavior. How do I use the advantages of both these containers? can I lay one over the other?
Yes you can lay the Canvas on top of a Grid, but you probably don't want to.
<Grid x:Name="container">
<!-- We use this to put the two items in the same location -->
<!-- i.e. Row="0" Column="0" is implicit for both the canvas and the grid below-->
<Grid x:Name="rectangleGrid"/>
<Canvas x:Name="shapeCanvas"/>
</Grid>
It really is that simple, but lets have a look at what we have now.
shapeCanvas
will be in front of the rectangleGrid
(and if it isn't just tweak its ZIndex
). If it has a non-transparent BackColor
then you won't of course see the rectangleGrid
, so you will need to sort that out.leftRectangle.ActualWidth + leftRectangle.Margin.Left + leftRectangle.Margin.Right + rightRectangle.Margin.Left + (rightRectangle.ActualWidth/2)
and topRectangle.ActualHeight + topRectangle.Margin.Top + someConstantForHowTallThatSpacerRowIs + rightRectangle.Margin.Top + (rightRectangle.Height/2)
. Ouchcontainer
, then the rectangleGrid
will also resize, but if you have used start-sizing for your columns then the rectangles all just resized. Now I have to go and recalculate all the sizes again. So at this point, I'd start asking myself if I really wanted the rectangleGrid
to handle the sizing or maybe I should just put everything into the Canvas
.
shapeCanvas.Size *11/16
and (shapeCanvas.Height - someConstantForHowTallThatSpacerRowIs)/14