如何在调整对象大小时保持其大小比例? [英] How to keep the size ratio of a object as it is re sized?
本文介绍了如何在调整对象大小时保持其大小比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将对象(让我们说一些按钮)放在网格的一列中.
用户可以在网格拆分器的帮助下更改列的宽度.
按钮的宽度应与列的宽度相同,并且每个按钮的高度均应与宽度相同.
我的问题是想出一种方法,使对象随着列宽的变化而改变其高度.
下面的XAML仅描述了我要完成的工作.
这没用.当实际宽度改变时,高度当然应该更新.
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!
推荐答案
将图像放入Viewbox
控件中,并将Stretch
属性设置为"Fill"
Put the image in aViewbox
control, and set theStretch
property to "Fill"
尝试一下:
< Viewbox Stretch ="Uniform">
< Button>点击</Button>
</Viewbox>
Try this:
<Viewbox Stretch="Uniform">
<Button>Click</Button>
</Viewbox>
这篇关于如何在调整对象大小时保持其大小比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文