c# – XAML TextBox isReadOnly Binding

我试图使用Windows 8.1应用程序中的Binding只读取文本框.我尝试过一些无法正常工作的代码.
你能提出任何最简单的方法吗,我对Binding这个概念很新.

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# – 文本框在加号前显示换行符


下一篇:在C#中限制对特定设备的输入