質問

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?

役に立ちましたか?

解決

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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top