【发布时间】:2012-01-25 18:57:14
【问题描述】:
我有以下代码:
<Window x:Class="UnderstandSizing.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" x:Name="Column1" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBox Grid.Column="0" Text="{Binding ActualWidth,ElementName=Column1,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Window>
我希望在文本框中看到 Column1 列的宽度值,但我只能看到 0。
我见过this 和this,但到处都说这仅与 Silverlight 有关,与 WPF 无关。
编辑 修正了一个错字。还要注意输出窗口不显示任何绑定问题。对我来说奇怪的是它在设计师中工作。它仅在运行时停止工作。
【问题讨论】:
-
你有一个错字。 “ElementName=Colum1”应该是“ElementName=Column1”
-
@theartwebreathe:不,在将代码放在 SO 时输入了错字:(