81 lines
2.0 KiB
C#
81 lines
2.0 KiB
C#
|
|
using MaterialDesignThemes.Wpf;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.CompilerServices;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
|||
|
|
{
|
|||
|
|
public class TreeItemModel : INotifyPropertyChanged
|
|||
|
|
{
|
|||
|
|
public bool IsUpdate = true;
|
|||
|
|
|
|||
|
|
private bool _isChecked;
|
|||
|
|
public bool IsChecked
|
|||
|
|
{
|
|||
|
|
get { return _isChecked; }
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_isChecked = value;
|
|||
|
|
|
|||
|
|
OnPropertyChanged();
|
|||
|
|
|
|||
|
|
if (Children.Count > 0)
|
|||
|
|
{
|
|||
|
|
SetChildrenCheck(value);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//if (Parent != null) Parent.IsChecked = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public int Id { get; set; }
|
|||
|
|
public string Name { get; set; }
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 父节点改变子节点
|
|||
|
|
private void SetChildrenCheck(bool isChecked)
|
|||
|
|
{
|
|||
|
|
foreach (var child in Children)
|
|||
|
|
{
|
|||
|
|
child.IsChecked = isChecked;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 子节点改变后,更新父节点状态
|
|||
|
|
private void UpdateParentState(bool isChecked)
|
|||
|
|
{
|
|||
|
|
if (Parent == null) return;
|
|||
|
|
|
|||
|
|
//bool anyChecked = Parent.Children.Any(x => x.IsChecked);
|
|||
|
|
Parent.IsChecked = isChecked;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 子节点
|
|||
|
|
public List<TreeItemModel> Children { get; set; } = new List<TreeItemModel>();
|
|||
|
|
|
|||
|
|
// 父节点(用于联动)
|
|||
|
|
public TreeItemModel Parent { get; set; }
|
|||
|
|
|
|||
|
|
public PackIconKind IconKind { get; set; }
|
|||
|
|
|
|||
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|||
|
|
{
|
|||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|