Question

I want to autostretch the control to fit a grid by width then set its height to what the grid width is.

Any ideas how I can accomplish this?

Was it helpful?

Solution

You can achieve that by Binding the Height Property to the ActualWidth Property of the Grid, you can even go further, for example if you want to set the height to be equals to two times of the width, by using a converter :

Code example 1 :

<Grid x:Name="ContentPanel" Grid.Row="1">
        <Button x:Name="Button" Content="Button" Width="200" Height="{Binding ElementName=ContentPanel, Path=ActualWidth}"/>
    </Grid>

Code example 2 :

<Grid x:Name="ContentPanel" Grid.Row="1">
            <Button x:Name="Button" Content="Button" Width="200" Height="{Binding ElementName=ContentPanel, Path=ActualWidth, Converter={StaticResource WidthToHeightConverter}}"/>
        </Grid>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top