csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
// Copyright (c) The Perspex Project. All rights reserved.
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Reactive;
|
|
using System.Reactive.Linq;
|
|
using Perspex.Controls;
|
|
using ReactiveUI;
|
|
|
|
namespace Perspex.Diagnostics.ViewModels
|
|
{
|
|
internal class TreeNode : ReactiveObject
|
|
{
|
|
private string _classes;
|
|
|
|
public TreeNode(Control control)
|
|
{
|
|
Control = control;
|
|
Type = control.GetType().Name;
|
|
|
|
var classesChanged = Observable.FromEventPattern<
|
|
NotifyCollectionChangedEventHandler,
|
|
NotifyCollectionChangedEventHandler>(
|
|
x => control.Classes.CollectionChanged += x,
|
|
x => control.Classes.CollectionChanged -= x);
|
|
|
|
classesChanged.Select(_ => Unit.Default)
|
|
.StartWith(Unit.Default)
|
|
.Subscribe(_ =>
|
|
{
|
|
if (control.Classes.Count > 0)
|
|
{
|
|
Classes = "(" + string.Join(" ", control.Classes) + ")";
|
|
}
|
|
else
|
|
{
|
|
Classes = string.Empty;
|
|
}
|
|
});
|
|
}
|
|
|
|
public IReadOnlyReactiveList<TreeNode> Children
|
|
{
|
|
get;
|
|
protected set;
|
|
}
|
|
|
|
public string Classes
|
|
{
|
|
get { return _classes; }
|
|
private set { this.RaiseAndSetIfChanged(ref _classes, value); }
|
|
}
|
|
|
|
public string Type
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public Control Control
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
}
|
|
}
|
|
|