添加项目文件。
This commit is contained in:
80
SamplePreSystem.UI/ViewModel/ConfigManager/TreeItemModel.cs
Normal file
80
SamplePreSystem.UI/ViewModel/ConfigManager/TreeItemModel.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user