C# 将IsEnabled属性绑定到WPF中的布尔值
我有一个C# 将IsEnabled属性绑定到WPF中的布尔值,c#,wpf,xaml,binding,isenabled,C#,Wpf,Xaml,Binding,Isenabled,我有一个文本框,需要以编程方式启用/禁用它。我希望通过绑定到布尔值来实现这一点。以下是文本框XAML: <TextBox Height="424" HorizontalAlignment="Left" Margin="179,57,0,0" Name="textBox2" VerticalAlignment="Top" Width="777" TextWrapping="WrapWit
文本框
,需要以编程方式启用/禁用它。我希望通过绑定到布尔值
来实现这一点。以下是文本框
XAML:
<TextBox Height="424" HorizontalAlignment="Left"
Margin="179,57,0,0" Name="textBox2"
VerticalAlignment="Top" Width="777"
TextWrapping="WrapWithOverflow"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
AcceptsReturn="True" AcceptsTab="True"
Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding Path=TextBoxEnabled}"/>
它不起作用。要提供更多信息,请通过以下方法更改TextBox_Enabled属性:
public void DisabledTextBox()
{
this.Textbox_Enabled = false;
}
…当按下组合键时会调用。这是您的小错误
private Boolean _textbox_enabled;
public Boolean TextboxEnabled // here, underscore typo
{
get { return _textbox_enabled; }
set
{
_textbox_enabled = value; // You miss this line, could be ok to do an equality check here to. :)
OnPropertyChanged("TextboxEnabled"); //
}
}
xaml还需要将文本更新到vm/datacontext
Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding TextBoxEnabled}"/>
Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding TextBoxEnabled}"/>