【发布时间】:2016-10-04 16:21:59
【问题描述】:
我有一个相当标准的设置:根据TextBox 的内容是否为空,我想启用/禁用Button 控件。
我试过了,什么在 WPF 应用程序中可以工作,但是在 Windows 运行时运行时不会产生所需的行为:
<StackPanel>
<TextBox x:Name="ItemNameTextBox" Header="Item" />
<Button Content="Add Item"
IsEnabled="{Binding ElementName=ItemNameTextBox,
Path=Text.Length,
Mode=OneWay}" />
</StackPanel>
但是,在运行时,这会产生以下调试输出1):
Error: BindingExpression path error: 'Length' property not found on 'Windows.Foundation.IReference`1<String>'.
错误消息是正确的:Windows::Foundation::IReference<String> 没有Length 属性。
问题:如何将Button 的IsEnabled 属性绑定到TextBoxs 文本长度属性?我必须实现自定义数据转换器,还是只能使用标记来完成?
1)完整的错误输出:
Error: BindingExpression path error: 'Length' property not found on 'Windows.Foundation.IReference`1<String>'. BindingExpression: Path='Text.Length' DataItem='Windows.UI.Xaml.Controls.TextBox'; target element is 'Windows.UI.Xaml.Controls.Button' (Name='null'); target property is 'IsEnabled' (type 'Boolean')
【问题讨论】:
标签: xaml windows-phone-8 windows-runtime winrt-xaml c++-cx