我用这个绑定错误把我的头撞在我的桌子上。我已经检查了几个帖子的BindingExpression
路径错误并且看不到任何适合我的情况的东西。
无论如何,我有一个名为IncrementingTextBox
. 每当用户“检查”上面的内容时,我都会尝试禁用CheckBox
它。
我有一个CheckBox
IsChecked
工作正常的属性绑定,并且在它应该触发的时候触发。它正确设置UseSensorLength
了 ConfigurationModel 上的属性。
但是,IncrementingTextBox
IsEnabled
属性上的绑定会导致BindingExpression
路径错误,因此根本不会更新。
作为测试,我尝试在后面的代码中启用和禁用控件,它工作得很好,但我似乎无法让绑定工作。
这是我的 xaml 的一个片段:
...
DataContext="{Binding RelativeSource={RelativeSource Self}}"
...
...
<CheckBox Content="Use Sensor Length" Margin="30,6,0,0"
IsChecked="{Binding ConfigurationModel.UseSensorLength, Mode=TwoWay}"/>
<local:IncrementingTextBox x:Name="video_length_textbox" Margin="0,0,0,5"
IsTextEnabled="False"
IsEnabled="{Binding ConfigurationModel.DontUseSensorLength}"
ValueChanged="VideoEventValueChanged"/>
这是我的 ConfigurationModel 的一个片段:
public bool DontUseSensorLength
{
get { return !UseSensorLength; }
}
public bool UseSensorLength
{
get { return _useSensorLength; }
set
{
_useSensorLength = value;
OnPropertyChanged("UseSensorLength");
OnPropertyChanged("DontUseSensorLength");
}
}
这是我在运行应用程序时在输出窗口中收到的错误消息:
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“IncrementingTextBox”(名称=“video_length_textbox”)上找不到“ConfigurationModel”属性。BindingExpression:Path=ConfigurationModel.DontUseSensorLength; DataItem='IncrementingTextBox' (Name='video_length_textbox'); 目标元素是'IncrementingTextBox'(名称='video_length_textbox');目标属性是“IsEnabled”(类型“布尔”)
请记住,“UseSensorLength”属性绑定工作正常,但“DontUseSensorLength”绑定导致上述“BindingExpression 路径错误”。