/// <summary>
        /// Adds the current element to the collection of selected items.
        /// </summary>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not
        /// intended to be used directly from your code.
        /// </remarks>
        void ISelectionItemProvider.AddToSelection()
        {
            TreeViewItem owner  = OwnerTreeViewItem;
            TreeView     parent = owner.ParentTreeView;

            if (parent == null || (parent.SelectedItem != null && parent.SelectedContainer != Owner))
            {
                throw new InvalidOperationException("Controls.Properties.Resources.Automation_OperationCannotBePerformed");
            }
            owner.IsSelected = true;
        }
Esempio n. 2
0
        void RefreshItem(mwc.TreeViewItem item)
        {
            if (item == null)
            {
                return;
            }
            var old = item.DataContext;

            item.DataContext = null;
            item.DataContext = old;
#if TODO_XAML
            item.InvalidateProperty(EtoTreeViewItem.IsExpandedProperty);
            item.HeaderTemplate = item.HeaderTemplate == template1 ? template2 : template1;
#endif
        }
        /// <summary>
        /// Hides all nodes, controls, or content that are descendants of the
        /// control.
        /// </summary>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not
        /// intended to be used directly from your code.
        /// </remarks>
        void IExpandCollapseProvider.Collapse()
        {
            if (!IsEnabled())
            {
                throw new ElementNotEnabledException();
            }

            TreeViewItem owner = OwnerTreeViewItem;

            if (!owner.HasItems)
            {
                throw new InvalidOperationException("Controls.Properties.Resources.Automation_OperationCannotBePerformed");
            }

            owner.IsExpanded = false;
        }
Esempio n. 4
0
        ///// <summary>
        ///// Gets the collection of child elements of the
        ///// <see cref="T:WinRTXamlToolkit.Controls.TreeView" /> that is associated
        ///// with this
        ///// <see cref="T:System.Windows.Automation.Peers.TreeViewAutomationPeer" />.
        ///// </summary>
        ///// <returns>The collection of child elements.</returns>
        //[SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists", Justification = "Required by automation")]
        //protected override List<AutomationPeer> GetChildrenCore()
        //{
        //    TreeView owner = OwnerTreeView;

        //    ItemCollection items = owner.Items;
        //    if (items.Count <= 0)
        //    {
        //        return null;
        //    }

        //    List<AutomationPeer> peers = new List<AutomationPeer>(items.Count);
        //    for (int i = 0; i < items.Count; i++)
        //    {
        //        TreeViewItem element = owner.ItemContainerGenerator.ContainerFromIndex(i) as TreeViewItem;
        //        if (element != null)
        //        {
        //            peers.Add(
        //                FrameworkElementAutomationPeer.FromElement(element) ??
        //                FrameworkElementAutomationPeer.CreatePeerForElement(element));
        //        }
        //    }

        //    return peers;
        //}

        /// <summary>
        /// Retrieves a UI automation provider for each child element that is
        /// selected.
        /// </summary>
        /// <returns>An array of UI automation providers.</returns>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not
        /// intended to be used directly from your code.
        /// </remarks>
        IRawElementProviderSimple[] ISelectionProvider.GetSelection()
        {
            IRawElementProviderSimple[] selection = null;

            TreeViewItem selectedItem = OwnerTreeView.SelectedContainer;

            if (selectedItem != null)
            {
                AutomationPeer peer = FrameworkElementAutomationPeer.FromElement(selectedItem);
                if (peer != null)
                {
                    selection = new IRawElementProviderSimple[] { ProviderFromPeer(peer) };
                }
            }

            return(selection ?? new IRawElementProviderSimple[] { });
        }
        /// <summary>
        /// Scrolls the content area of a container object in order to display
        /// the control within the visible region (viewport) of the container.
        /// </summary>
        /// <remarks>
        /// This API supports the .NET Framework infrastructure and is not
        /// intended to be used directly from your code.
        /// </remarks>
        void IScrollItemProvider.ScrollIntoView()
        {
            // Note: WPF just calls BringIntoView on the current TreeViewItem.
            // This actually raises an event that can be handled by the
            // its containers.  Silverlight doesn't support this, so we will
            // approximate by moving scrolling the TreeView's ScrollHost to the
            // item.

            // Get the parent TreeView
            TreeViewItem owner  = OwnerTreeViewItem;
            TreeView     parent = owner.ParentTreeView;

            if (parent == null)
            {
                return;
            }

            // Scroll the item into view
            parent.ItemsControlHelper.ScrollIntoView(owner);
        }
Esempio n. 6
0
        /// <summary>
        /// Select any descendents when adding new TreeViewItems to a TreeView.
        /// </summary>
        /// <param name="item">The added item.</param>
        internal void CheckForSelectedDescendents(TreeViewItem item)
        {
            Debug.Assert(item != null, "item should not be null!");

            Stack<TreeViewItem> items = new Stack<TreeViewItem>();
            items.Push(item);

            // Recurse into subtree of each added item to ensure none of
            // its descendents are selected.
            while (items.Count > 0)
            {
                TreeViewItem current = items.Pop();
                if (current.IsSelected)
                {
                    // Make IsSelected false so that its property changed
                    // handler will be fired when it's set to true in
                    // ChangeSelection
                    current.IgnorePropertyChange = true;
                    current.IsSelected = false;

                    ChangeSelection(current, current, true);

                    // If the item is not in the visual tree, we will make sure
                    // every check for ContainsSelection will try and update the
                    // sequence of ContainsSelection flags for the
                    // SelectedContainer.
                    if (SelectedContainer.ParentItemsControl == null)
                    {
                        SelectedContainer.RequiresContainsSelectionUpdate = true;
                    }
                }
                foreach (TreeViewItem nestedItem in current.Items.OfType<TreeViewItem>())
                {
                    items.Push(nestedItem);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Change whether a TreeViewItem is selected.
        /// </summary>
        /// <param name="itemOrContainer">
        /// Item whose selection is changing.
        /// </param>
        /// <param name="container">
        /// Container of the item whose selection is changing.
        /// </param>
        /// <param name="selected">
        /// A value indicating whether the TreeViewItem is selected.
        /// </param>
        internal void ChangeSelection(object itemOrContainer, TreeViewItem container, bool selected)
        {
            // Ignore any change notifications if we're alread in the middle of
            // changing the selection
            if (IsSelectionChangeActive)
            {
                return;
            }

            object oldValue = null;
            object newValue = null;
            bool raiseSelectionChanged = false;
            TreeViewItem element = SelectedContainer;

            // Start changing the selection
            IsSelectionChangeActive = true;
            try
            {
                if (selected && container != SelectedContainer)
                {
                    // Unselect the old value
                    oldValue = SelectedItem;
                    if (SelectedContainer != null)
                    {
                        SelectedContainer.IsSelected = false;
                        SelectedContainer.UpdateContainsSelection(false);
                    }

                    // Select the new value
                    newValue = itemOrContainer;
                    SelectedContainer = container;
                    SelectedContainer.UpdateContainsSelection(true);
                    SelectedItem = itemOrContainer;
                    UpdateSelectedValue(itemOrContainer);
                    raiseSelectionChanged = true;

                    // Scroll the selected item into view.  We only want to
                    // scroll the header into view, if possible, because an
                    // expanded TreeViewItem contains all of its child items
                    // as well.
                    ItemsControlHelper.ScrollIntoView(container.HeaderElement ?? container);
                }
                else if (!selected && container == SelectedContainer)
                {
                    // Unselect the old value
                    SelectedContainer.UpdateContainsSelection(false);
                    SelectedContainer = null;
                    SelectedItem = null;
                    SelectedValue = null;
                    oldValue = itemOrContainer;
                    raiseSelectionChanged = true;
                }

                container.IsSelected = selected;
            }
            finally
            {
                // Finish changing the selection
                IsSelectionChangeActive = false;
            }

            // Notify when the selection changes
            if (raiseSelectionChanged)
            {
                if (SelectedContainer != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected))
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(SelectedContainer);
                    if (peer != null)
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                    }
                }
                if (element != null && AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection))
                {
                    AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(element);
                    if (peer != null)
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection);
                    }
                }

                OnSelectedItemChanged(new RoutedPropertyChangedEventArgs<object>(oldValue, newValue));
            }
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" />
 /// class.
 /// </summary>
 /// <param name="owner">
 /// The <see cref="T:WinRTXamlToolkit.Controls.TreeViewItem" /> instance
 /// to associate with this
 /// <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" />.
 /// </param>
 public TreeViewItemAutomationPeer(TreeViewItem owner)
     : base(owner)
 {
 }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" />
 /// class.
 /// </summary>
 /// <param name="owner">
 /// The <see cref="T:WinRTXamlToolkit.Controls.TreeViewItem" /> instance
 /// to associate with this
 /// <see cref="T:System.Windows.Automation.Peers.TreeViewItemAutomationPeer" />.
 /// </param>
 public TreeViewItemAutomationPeer(TreeViewItem owner)
     : base(owner)
 {
 }