绑定到ColumnDefinition.ActualWidth返回0 [英] Binding to ColumnDefinition.ActualWidth returns 0

查看:501
本文介绍了绑定到ColumnDefinition.ActualWidth返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

粘贴到苹果酒这一点。

<Grid x:Name="Grid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition x:Name="ColumnDefinition"/>
    </Grid.ColumnDefinitions>
    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock Text="{Binding ActualWidth, ElementName=Grid}"/>
        <TextBlock Text="{Binding ActualWidth, ElementName=ColumnDefinition}"/>
    </StackPanel>
</Grid>

现在,运行它。第二个的TextBlock 显示0,但应该不会,对不对?解决方法?

Now, run it. The second TextBlock shows 0, but shouldn't, right? Workaround?

推荐答案

没有,你没有。 ColumnDefinition确实有一个 ActualWidth的属性,其实。但它既不的DependencyProperty 也有 INotifyPropertyChanged的的实施。所以没有人让你的目标什么时候 ActualWidth的更新。

No, you didn't. ColumnDefinition does have an ActualWidth property, actually. But it's neither DependencyProperty nor there INotifyPropertyChanged implementation. So nobody let your target know when ActualWidth is updated.

解决方法?为了什么?您可以随时使用的ElementName 绑定到谁拥有完全父 FrameworkElement的,即 ActualWidth的你想要的。对不起,复杂的短语:)。无法变得更简单。

Workaround? For what? You can always use ElementName binding to the parent FrameworkElement, who has exactly that ActualWidth that you wanted. Sorry for complex phrase :). Couldn't make it simpler.

希望这有助于。

这篇关于绑定到ColumnDefinition.ActualWidth返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆