using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kingo.Plugin.BGResultManager.Model { public class XZQTreeNode : INotifyPropertyChanged { /// /// /// ///create 王欢 2018-09-29 public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } /// /// IsChecked /// ///Update 王欢 2018-09-28 private bool _isChecked; public bool IsChecked { set { _isChecked = value; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); SetIsCheckedByParent(value); if (Parent != null) Parent.SetIsCheckedByChild(value); } get { return this._isChecked; } } public string XZQMC { get; set; } public string XZQDM { get; set; } public decimal XH { get { decimal xh; decimal.TryParse(XZQDM, out xh); return xh; } } public string ShowName { get { if (string.IsNullOrEmpty(XZQMC)) { XZQMC = XZQDM; } return string.Format("{0}[{1}]", XZQMC, XZQDM); } } public object Tag { get; set; } public string GroupName { get; set; } public bool IsExpanded { get; set; } public XZQTreeNode Parent { get; set; } /// /// 子节点,默认null /// ///Update 王欢 2018-09-29 private List _nodes = new List(); public IList Nodes { get { return _nodes; } set { _nodes = (List)value; } } #region 王欢 2018-09-28 /// /// 子节点的isChecked改变了, 通知父节点是否要跟着改变 isChecked /// /// public virtual void SetIsCheckedByChild(bool value) { if (this._isChecked == value) { return; } bool isAllChildrenChecked = this.Nodes.All(c => c.IsChecked == true); this._isChecked = isAllChildrenChecked; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); if (Parent != null) Parent.SetIsCheckedByChild(value); } /// /// 父节点isChecked改变了, 所有子节点跟着改变 /// /// public virtual void SetIsCheckedByParent(bool value) { this._isChecked = value; if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs("IsChecked")); if (Nodes == null) { return; } foreach (var child in Nodes) { child.SetIsCheckedByParent(value); } } #endregion } }