public void SetIsChecked(bool?value, bool updateChildren, bool updateParent) { if (value == mIsChecked) { return; } mIsChecked = value; if (updateChildren && mIsChecked.HasValue) { foreach (var child in Children) { ICheckableItem checkableItem = child; if (checkableItem != null) { checkableItem.SetIsChecked(mIsChecked, true, false); } } } if (updateParent && mParent != null) { ICheckableItem parent = mParent; if (parent != null) { parent.VerifyCheckState(); } } OnPropertyChanged("IsChecked"); }
/// <summary> /// 检查元素状态 /// </summary> public void VerifyCheckState() { bool?state = null; for (int i = 0; i < Children.Count; ++i) { ICheckableItem checkableItem = Children[i]; if (checkableItem == null) { continue; } bool?current = checkableItem.IsChecked; if (i == 0) { state = current; } else if (state != current) { state = null; break; } } SetIsChecked(state, false, true); }