コード例 #1
0
        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckBoxTreeView dp = (CheckBoxTreeView)d;

            if (dp._treeView != null)
            {
                dp._treeView.ItemsSource = e.NewValue as IEnumerable;
            }
        }
コード例 #2
0
        private static void OnItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckBoxTreeView dp = (CheckBoxTreeView)d;

            if (dp._treeView != null)
            {
                dp._treeView.ItemTemplate = e.NewValue as DataTemplate;
            }
        }
コード例 #3
0
        private static object CoerceIsDropDownOpen(DependencyObject d, object baseValue)
        {
            if ((bool)baseValue)
            {
                CheckBoxTreeView cb = (CheckBoxTreeView)d;
                if (!cb.IsLoaded)
                {
                    //cb.RegisterToOpenOnLoad();
                    return(false);
                }
            }

            return(baseValue);
        }
コード例 #4
0
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckBoxTreeView ctv = d as CheckBoxTreeView;

            if (e.NewValue != null)
            {
                if (e.NewValue.ToString() != ctv._textBox.Text)
                {
                    ctv._textBox.Text = e.NewValue.ToString();
                }
            }
            else
            {
                ctv._textBox.Text = null;
            }
        }
コード例 #5
0
        private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckBoxTreeView cb = (CheckBoxTreeView)d;

            if (cb._poup != null)
            {
                if ((bool)e.NewValue)
                {
                    cb.Dispatcher.BeginInvoke(DispatcherPriority.Send, (DispatcherOperationCallback) delegate(object arg)
                    {
                        //展开所有子节点
                        if (cb._treeView != null && cb.ItemsSource != null)
                        {
                            foreach (var item in cb._treeView.Items)
                            {
                                if (item is MultiSelectionTreeViewItem)
                                {
                                    (item as MultiSelectionTreeViewItem).IsExpanded = true;
                                }
                                else
                                {
                                    MultiSelectionTreeViewItem tvi = cb._treeView.ItemContainerGenerator.ContainerFromItem(item) as MultiSelectionTreeViewItem;
                                    if (tvi != null)
                                    {
                                        if (!tvi.IsExpanded)
                                        {
                                            tvi.IsExpanded = true;
                                        }
                                        //如果子项还没有初始化容器,则刷新布局获取容器,保证取遍历的时候取到
                                        if (tvi.ItemContainerGenerator.Status != System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
                                        {
                                            tvi.UpdateLayout();
                                        }
                                        tvi.ExpandAllChildren();
                                    }
                                }
                            }
                        }
                        return(null);
                    }, cb);
                }
            }
        }