private void OnChildRemoved(TreeGridElement child) { // Clear the model for the child child.SetModel(null); // Notify the model that a child was removed from the item Model?.OnChildRemoved(child); }
/// <summary> /// /// </summary> /// <param name="item"></param> private void OnChildAdded(object item) { // Verify the new child TreeGridElement child = VerifyItem(item); // Set the model for the child child.SetModel(Model, this); // Notify the model that a child was added to the item Model?.OnChildAdded(child); }
/// <summary> /// /// </summary> /// <param name="oldChild"></param> /// <param name="item"></param> /// <param name="index"></param> private void OnChildReplaced(TreeGridElement oldChild, object item, int index) { // Verify the new child TreeGridElement child = VerifyItem(item); // Clear the model for the old child oldChild.SetModel(null); // Notify the model that a child was replaced Model?.OnChildReplaced(oldChild, child, index); }
/// <summary> /// 设置模型 /// </summary> /// <param name="model"></param> /// <param name="parent"></param> internal void SetModel(TreeGridModel model, TreeGridElement parent = null) { // 设置元素信息 Set the element information Model = model; Parent = parent; Level = (parent != null) ? parent.Level + 1 : 0; // 遍历所有子元素 foreach (TreeGridElement child in Children) { // 为孩子设定模型 Set the model for the child child.SetModel(model, this); } }
/// <summary> /// 已展开改变事件 /// </summary> /// <param name="element"></param> /// <param name="args"></param> private static void OnIsExpandedChanged(DependencyObject element, DependencyPropertyChangedEventArgs args) { // 获取树项 Get the tree item TreeGridElement item = (TreeGridElement)element; // Is the item being expanded? if ((bool)args.NewValue) { // Raise expanding event item.RaiseEvent(new RoutedEventArgs(ExpandingEvent, item)); // Execute derived expanding handler item.OnExpanding(); // Expand the item in the model item.Model?.Expand(item); // Raise expanded event item.RaiseEvent(new RoutedEventArgs(ExpandedEvent, item)); // Execute derived expanded handler item.OnExpanded(); } else { // Raise collapsing event item.RaiseEvent(new RoutedEventArgs(CollapsingEvent, item)); // Execute derived collapsing handler item.OnCollapsing(); // Collapse the item in the model item.Model?.Collapse(item); // Raise collapsed event item.RaiseEvent(new RoutedEventArgs(CollapsedEvent, item)); // Execute derived collapsed handler item.OnCollapsed(); } }