1
我有一個ReactiveObject:ReactiveUI變化觀察的通知,有奇怪的順序
public class Example : ReactiveObject
{
private string _commonProperty;
public string CommonProperty
{
get { return _commonProperty; }
set { this.RaiseAndSetIfChanged(ref _commonProperty, value); }
}
private readonly ObservableAsPropertyHelper<string> _dependent;
public string DependentProperty => _dependent.Value;
public Example()
{
_dependent = this.WhenAnyValue(e => e.CommonProperty)
.Select(s => s?.ToUpper())
.ToProperty(this, e => e.DependentProperty);
}
}
當我改變CommonProperty的價值的PropertyChanged事件和更改的可觀測項目的順序是不一樣的。
例如:
var example = new Example();
example.PropertyChanged += (sender, args) => Console.WriteLine("Event: " + args.PropertyName);
example.Changed.Subscribe(args => Console.WriteLine("Changed Observable: " + args.PropertyName));
example.CommonProperty = "newValue";
打印
Event: CommonProperty
Event: DependentProperty
Changed Observable: DependentProperty
Changed Observable: CommonProperty
活動已期待的順序,但改變觀察的不是。 所以問題是爲什麼Changed Observable:DependentProperty之前Changed Observable:CommonProperty?
而且,我希望這樣的輸出:
Event: CommonProperty
Changed Observable: CommonProperty
Event: DependentProperty
Changed Observable: DependentProperty
爲什麼大約相同的屬性事件和觀察的通知是分開的?
謝謝!我絕對同意我不應該依賴它。我只是預料到事件和觀察者的通知順序將是相同的,如果不是這樣,我認爲我做錯了什麼。 – Inok