Example #1
0
        /// <summary>
        /// Select/unselect a node.
        /// All parent nodes up to root must already be expanded.
        /// Otherwise there is no effect.
        /// </summary>
        /// <param name="data">The data that the target node contains</param>
        /// <param name="selected">true: select the node; false: unselect the node</param>
        public void SelectItem(object data, bool selected)
        {
            int index;
            TreeGridViewItemInfo info = this.FindItemInfoForData(data, out index);

            if (info != null)
            {
                this.ScrollIntoView(info);

                this.Dispatcher.BeginInvoke(
                    (Action)(() =>
                {
                    TreeGridViewItem container = this.ItemContainerGenerator.ContainerFromIndex(index) as TreeGridViewItem;
                    if (container != null)
                    {
                        container.IsSelected = selected;
                    }
                }),
                    System.Windows.Threading.DispatcherPriority.Background);
            }
        }
Example #2
0
        // Callback function for IsExpanded dependency property
        // all it does is to ask parent view to expand/collapse the item accordingly
        private static void OnIsExpandedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TreeGridViewItem container = (TreeGridViewItem)d;
            var info = container.DataContext as TreeGridViewItemInfo;

            bool oldValue = (bool)e.OldValue;
            bool newValue = (bool)e.NewValue;

            if (oldValue == false && newValue == true)
            {
                if (container.ParentView != null && info != null)
                {
                    container.ParentView.ExpandItem(info.Data);
                }
            }
            else if (oldValue == true && newValue == false)
            {
                if (container.ParentView != null && info != null)
                {
                    container.ParentView.CollapseItem(info.Data);
                }
            }
        }
Example #3
0
 /// <summary>
 /// Called by an item to notify the view when it gets focus
 /// The view has to know the currently focused item
 /// </summary>
 /// <param name="childItem">the child item got focus</param>
 internal void NotifyItemGotFocus(TreeGridViewItem childItem)
 {
     this.focusItemInfo = this.ItemContainerGenerator.ItemFromContainer(childItem) as TreeGridViewItemInfo;
     // clear the pending focus restore since a new focus is set by user
     this.restoreFocusItemInfo = null;
 }