Пример #1
0
        private static void OnExpandedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CustomTreeViewItem treeViewItem = d as CustomTreeViewItem;

            if ((bool)e.NewValue)
            {
                RoutedEventArgs args = new RoutedEventArgs(ExpandedEvent, treeViewItem);
                treeViewItem.RaiseEvent(args);
            }
            else
            {
                RoutedEventArgs args = new RoutedEventArgs(CollapsedEvent, treeViewItem);
                treeViewItem.RaiseEvent(args);
            }
        }
Пример #2
0
        internal void SetIsSelect(CustomTreeViewItem treeViewItem, bool?isSelected)
        {
            if (treeViewItem == null)
            {
                return;
            }
            CustomTreeView tree   = GetParentTreeView();
            ItemsControl   parent = ItemsControl.ItemsControlFromItemContainer(treeViewItem);

            if (tree != null && parent != null)
            {
                object data = parent.ItemContainerGenerator.ItemFromContainer(treeViewItem);
                tree.ChangeSelection(data, treeViewItem, isSelected);
                if (IsSelected.HasValue)
                {
                    if (IsSelected.Value)
                    {
                        RoutedEventArgs args = new RoutedEventArgs(SelectedEvent, treeViewItem);
                        treeViewItem.RaiseEvent(args);
                    }
                    else
                    {
                        RoutedEventArgs args = new RoutedEventArgs(UnselectedEvent, treeViewItem);
                        treeViewItem.RaiseEvent(args);
                    }
                }
            }
            if (tree.SelectMode != SelectionMode.Single)
            {
                treeViewItem.IsExpanded = true;
                treeViewItem.UpdateLayout();
                for (int i = 0; i < treeViewItem.Items.Count; i++)
                {
                    CustomTreeViewItem subItem = (CustomTreeViewItem)treeViewItem.ItemContainerGenerator.ContainerFromIndex(i);
                    SetIsSelect(subItem, isSelected);
                }

                CascadingSetParentIsSelected(parent as CustomTreeViewItem);
            }
        }