views:

47

answers:

2

Here is a simple XAML snippet:

<Grid x:Name="ContentGrid"> <ContentControl Background="Yellow" VerticalAlignment="Stretch"></ContentControl> </Grid>

In WPF, the content control stretches the entire height of the grid.

In WP7 however, the content control does not stretch.

Why?

A: 

Avoid using ContentControl directly.
If you use something which inherits from it, such as a button, then, in a grid, as per your example, you'll automatically get horizontal and vertical stretching.
This will creat a button with a yellow background which fills the screen:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Button Background="Yellow" />
</Grid>

However, if you just wanted a yellow background to your grid - which is all your sample would do - you could just set the background property on the grid itself.

Matt Lacey
Sure, but _why_ doesn't stretch work for ContentControls?
A: 

I fixed this by defining my own template:

<ContentControl><ContentControl.Template><ControlTemplate><ContentPresenter/> ...

Not sure why it fixes it but it works....