And*_*ech 47 size wpf width actualwidth
我目前正在使用PanelWPF中的s,我注意到关于Width和Height属性,还有另外两个属性叫做ActualWidth和ActualHeight.
ActualWidth获取此元素的呈现宽度.这是一个依赖属性.(继承自FrameworkElement.)
Width获取或设置元素的宽度.这是一个依赖属性.(继承自FrameworkElement.)
参考:MSDN
任何人都可以指出两者之间的差异以及何时使用其中任何一个?
Mua*_*Dib 70
Width/ Height是请求的或布局大小.如果设置为"自动",则该值是double.NaN在后面的代码中访问属性时的值.
ActualWidth/ ActualHeight是渲染的大小.如果您需要/需要项目的实际大小,请使用此属性.
ActualWidth当我想将一个元素的宽度或高度绑定到另一个元素时,我觉得最有用.
在这个简单的例子中,我有两个并排排列的按钮,下面的注释被约束到包含两个按钮的StackPanel的宽度.
<StackPanel>
<StackPanel Margin="0,12,0,0" Orientation="Horizontal" Name="buttonPanel" HorizontalAlignment="Left" >
<Button Content="Yes - Arm the missile" FontWeight="Bold" HorizontalAlignment="Left"/>
<Button Content="No - Save the world" HorizontalAlignment="Left" Margin="7,0,0,0"/>
</StackPanel>
<TextBlock Text="Please choose whether you want to arm the missile and kill everybody, or save the world by deactivating the missile."
Width="{Binding Path=ActualWidth,ElementName=buttonPanel}" Margin="0,5,0,0" HorizontalAlignment="Left" TextWrapping="Wrap"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
ActualWidth在值中填充填充因此,只要您需要知道该号码,您可以调用Actualwidth而不是宽度并避免计算.
编辑:删除保证金b/c它不是ActualWidth的一部分.
| 归档时间: |
|
| 查看次数: |
48291 次 |
| 最近记录: |