只有当另一个属性设置为true时,我才试图验证属性。我使用的是RequiredIfAttribute,这是从另一个网页。
[RequiredIf("PropertyA",true)]
public string PropertyB
{
get
{
return _PropertyB;
}
set
{
this.RaiseAndSetifChanged(x => x.PropertyB, value);
}
}RequiredIf属性正在检查是否将PropertyA设置为true,然后验证,否则它将跳过验证并返回成功。它工作起来很有魅力,但问题是,只有当PropertyB被更改时,它才能工作,但它不知道当PropertyA被更改时它需要刷新。因此,当PropertyA被更改如下时,我试图强制进行更新:
this.ObservableForProperty(x => x.PropertyA).Subscribe(obj =>
{
this.RaisePropertyChanged(x=>x.PropertyB);
})但这不管用-什么都没发生。我认为它被忽略了,因为它的价值没有改变。
还有一种方法是可行的,但它是一种解决办法,而不是解决方案:
this.ObservableForProperty(x=>x.PropertyA).Subscribe(obj =>
{
var temp = PropertyB;
PropertyB = "anything"; //it forces revalidation
PropertyB = temp; // it forces revalidation
})发布于 2016-01-27 12:12:32
我希望在这种情况下,将PropertyA与PropertyB绑定在一起将对您有所帮助。
https://stackoverflow.com/questions/35036693
复制相似问题