Click here to Skip to main content
15,913,487 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have objects (lets say buttons) placed in a column in a grid.
The width of the column can be changed by the user with help of a grid splitter.
The buttons should have the same width as the column and each of them should have the same height as width.

My problem is to figure out a way to make the objects change their height as the width of the column changes.

The XAML below just describes what I want to accomplish.
It does not work. The height should of course be updated when the actual width changes.

<Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition Width="2"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <controls:GridSplitter Grid.Row="1" Grid.Column="1" Grid.RowSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowsPreview="True" />
            <Grid Name="widgetPanel"  Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">
                <StackPanel>
                    <Button Height="{Binding ActualWidth, ElementName=_widgetPanel}" />
                    <Button Height="{Binding ActualWidth, ElementName=_widgetPanel}" />
                    <Button Height="{Binding ActualWidth, ElementName=_widgetPanel}" />
                    <Button Height="{Binding ActualWidth, ElementName=_widgetPanel}" />
                </StackPanel>
            </Grid>
</Grid>

Any suggestions are welcome!
Posted
Updated 3-Sep-10 5:20am
v3
Comments
Dalek Dave 3-Sep-10 11:20am    
Edited for Spelling, Grammar, Readability and Code Block.

Try this:


<Viewbox Stretch="Uniform">
<Button>Click</Button>
</Viewbox>
 
Share this answer
 
Put the image in a Viewbox control, and set the Stretch property to "Fill"
 
Share this answer
 
Comments
jakopberg 3-Sep-10 11:24am    
Will that actually make the height = width?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900