C# 带有DataAnnotation的ReactiveValidatedObject强制重新验证属性

C# 带有DataAnnotation的ReactiveValidatedObject强制重新验证属性,c#,.net,wpf,reactiveui,C#,.net,Wpf,Reactiveui,仅当另一个属性设置为true时,我才尝试验证该属性。我使用的是另一个网页上的RequirediftAttribute [RequiredIf("PropertyA",true)] public string PropertyB { get { return _PropertyB; } set { this.RaiseAndSetifChanged(x => x.PropertyB, value); }

仅当另一个属性设置为true时,我才尝试验证该属性。我使用的是另一个网页上的RequirediftAttribute

[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
})

我希望绑定PropertyA和PropertyB能在这种情况下帮助您。

不确定您的意思,您能提供更多详细信息吗?