views:

1378

answers:

1

I have a Border inside a Canvas. The Border's height/width are varying according to its contents. I want the Border to stretch out to fill up the entire Canvas. How can I do that?

I have tried this on the Border without success:

Height="{Binding ElementName=MainCanvas, Path=Height}" 
Width="{Binding ElementName=MainCanvas, Path=Width}"
+5  A: 

Does the canvas have an explicit height/width? It may be auto sizing and have a height/width of double.NaN.

Try binding the child height/width to the ActualHeight and ActualWidth of canvas like so:

Height="{Binding ElementName=MainCanvas, Path=ActualHeight}"
Width="{Binding ElementName=MainCanvas, Path=ActualWidth}"

Canvas Panels never tell children to size relative to their size, even when the children are set to HorizontalAlignment.Stretch (or vertical). So binding is a good solution here.

Josh G
Thanks a lot Josh! I needed ActualHeight/ActualWidth as opposed to Height/Width.
Gustavo Cavalcanti