【发布时间】:2016-01-17 05:31:24
【问题描述】:
我正在尝试使用 Windows 8.1 应用程序中的绑定将文本框设为只读。我尝试了一些来自互联网的代码,但它不起作用。 你能建议任何最简单的方法吗,我对绑定这个概念很陌生。
XAML
<TextBox x:Name="tbOne" IsReadOnly="{Binding Path=setread, Mode=OneWay}" />
<Button Content="isReadonlyBinding" x:Name="isReadonlyBinding" Click="isReadonlyBinding_Click"></Button>
XAML.CS
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(
"setread",
typeof(bool),
typeof(MainPage),
new PropertyMetadata(false)
);
public bool setread
{
get { return (bool)GetValue(IsReadOnlyProperty); }
set { SetValue(IsReadOnlyProperty, value); }
}
private void isReadonlyBinding_Click(object sender, RoutedEventArgs e)
{
setread = true;
}
【问题讨论】:
-
您不需要在
setread上使用RaisePropertyChanged吗?我不太确定它在 Windows 应用程序上的运行情况。
标签: c# xaml binding textbox windows-8.1