我正在尝试使用 Windows 8.1 应用程序中的绑定(bind)将文本框设置为只读。我已经尝试了一些来自互联网的代码,但它们不起作用。 你能建议任何最简单的方法吗,我对绑定(bind)这个概念还很陌生。
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;
}
最佳答案
试试这个。
<page X:name="PageName">
IsReadOnly="{Binding ElementName=PageName,Path=setread, Mode=OneWay}"
关于c# - XAML TextBox isReadOnly 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33204760/