如何观察树的任何子层的属性更改?在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