如何觀察樹的任何子層的屬性更改?在Rx.NET中使用樹/ ReactiveUI
考慮例如具有屬性Name
和ChildNodes
的屬性TreeNode
。如何觀察Name
任何子級的變化TreeNode
?
的使用可能是這個樣子:
rootNode.FlattenTreeToObservable(x => x.ChildNodes)
.WhenAnyValue(x => x.Name)
.Subscribe(...)
樹節點例如:
// NuGet: Install-Package reactiveui
// In case of Splat version issue: Install-Package Splat -Version 1.6.2
using ReactiveUI;
public class TreeNode: ReactiveObject
{
public string Name
{
get { return this._name; }
set { this.RaiseAndSetIfChanged(ref this._name, value); }
}
private string _name = "";
public ReactiveList<TreeNode> ChildNodes
{
get { return this._childNodes; }
set { this.RaiseAndSetIfChanged(ref this._childNodes, value); }
}
private ReactiveList<TreeNode> _childNodes = new ReactiveList<TreeNode>();
}
請提供TreeNode'的'滿級定義以及任何支持類。你應該儘可能簡單地讓我們回答。 – Enigmativity
他們完全對我很重要。如果你能提供具體的課程,那麼你會讓人們回答。否則,你要求我們設計一個系統。這在艱苦工作中太過分了。就像我說過的,你應該儘可能簡單地讓我們回答。 – Enigmativity
什麼是RaiseAndSetIfChanged?我試圖複製,粘貼和編譯你的代碼。 – Enigmativity