示例#1
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.AddValueChanged(TreeViewItemEx.IsDraggingOverProperty, (o, e) =>
     {
         TreeViewItemEx tvItem = o as TreeViewItemEx;
         if (tvItem.IsDraggingOver && ExpandIfDragOver)
         {
             DispatcherTimer dispatcherTimer = new DispatcherTimer();
             EventHandler onTick             = null;
             onTick = (o1, e1) =>
             {
                 if (tvItem.IsDraggingOver)
                 {
                     tvItem.SetValue(TreeViewItem.IsExpandedProperty, true);
                 }
                 dispatcherTimer.Tick -= onTick;
                 dispatcherTimer.Stop();
             };
             dispatcherTimer.Tick    += onTick;
             dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
             dispatcherTimer.Start();
         }
     });
 }
示例#2
0
        public TreeViewItemEx()
        {
            this.AddHandler(TreeViewItem.SelectedEvent, new RoutedEventHandler(
                                (RoutedEventHandler) delegate(object obj, RoutedEventArgs args)
            {
                if (args.OriginalSource is TreeViewItem)
                {
                    (args.OriginalSource as TreeViewItem).BringIntoView();
                }
            }));

            this.AddValueChanged(TreeViewItemEx.IsBringIntoViewProperty, (o, e) =>
            {
                TreeViewItemEx tvItem = o as TreeViewItemEx;
                if (tvItem.IsBringIntoView)
                {
                    this.BringIntoView();
                    tvItem.IsBringIntoView = false;
                }
            });
        }