我在 C# 库类中有一个实体类并链接到 Silverlight 类库(实体必须在 C# 类中,因为与其他系统的遗留兼容性)
示例(C# 库):
public class TestClass
{
private string _testValue;
public string TestValue
{
get { return _testValue; }
set
{
if (_testValue!= value)
{
_testValue = value;
OnPropertyChanged("TestValue");
}
}
}}
此类链接到 Silverlight 类库。
在 MVVM 上有一个属性
private TestClass _testProp = new TestClass();
public TestClass TestProp
{
get
{
return _testProp ;
}
set
{
if (value != _testProp )
{
_testProp = value;
RaisePropertyChanged("TestProp");
PressCommand.CanExecuteChanged();
}
}
}
该属性绑定到 XAML 中的控件
<TextBox Text="{Binding TestProp.TestValue, Mode=TwoWay}">
<Button Content="Press" Command="{Binding PressCommand}" />
我想用 RelayCommands CanExecute 控制按钮取决于 TestClass 中的 TestValue ...
PressCommand = new RelayCommand(() =>
{
DoSomething();
}, () => TestProp.TestValue != string.empty);
但是,如果 TestValue 更改(与空字符串不同),PressCommand CanExecute 似乎没有注意到更改并且未启用,使其无法使用...
是否可以将 CanExecute 与这种 set-tu 一起使用