当前位置: 首页>>代码示例>>C#>>正文


C# TreeViewItem.UpdateContainsSelection方法代码示例

本文整理汇总了C#中System.Windows.Controls.TreeViewItem.UpdateContainsSelection方法的典型用法代码示例。如果您正苦于以下问题:C# TreeViewItem.UpdateContainsSelection方法的具体用法?C# TreeViewItem.UpdateContainsSelection怎么用?C# TreeViewItem.UpdateContainsSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.TreeViewItem的用法示例。


在下文中一共展示了TreeViewItem.UpdateContainsSelection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ChangeSelection

        /// <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));
            }
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:96,代码来源:TreeView.cs

示例2: ChangeSelection

        internal void ChangeSelection(object data, TreeViewItem container, bool selected) 
        { 
            if (IsSelectionChangeActive)
            { 
                return;
            }

            object oldValue = null; 
            object newValue = null;
            bool changed = false; 
            TreeViewItem oldContainer = _selectedContainer; // Saved for the automation event 

            IsSelectionChangeActive = true; 

            try
            {
                if (selected) 
                {
                    if (container != _selectedContainer) 
                    { 
                        oldValue = SelectedItem;
                        newValue = data; 

                        if (_selectedContainer != null)
                        {
                            _selectedContainer.IsSelected = false; 
                            _selectedContainer.UpdateContainsSelection(false);
                        } 
                        _selectedContainer = container; 
                        _selectedContainer.UpdateContainsSelection(true);
                        SetSelectedItem(data); 
                        UpdateSelectedValue(data);
                        changed = true;
                    }
                } 
                else
                { 
                    if (container == _selectedContainer) 
                    {
                        _selectedContainer.UpdateContainsSelection(false); 
                        _selectedContainer = null;
                        SetSelectedItem(null);

                        oldValue = data; 
                        changed = true;
                    } 
                } 

                if (container.IsSelected != selected) 
                {
                    container.IsSelected = selected;
                }
            } 
            finally
            { 
                IsSelectionChangeActive = false; 
            }
 
            if (changed)
            {
                if (    _selectedContainer != null
                    &&  AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementSelected)   ) 
                {
                    TreeViewItemAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(_selectedContainer) as TreeViewItemAutomationPeer; 
                    if (peer != null) 
                        peer.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementSelected);
                } 

                if (    oldContainer != null
                    &&  AutomationPeer.ListenerExists(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection)   )
                { 
                    TreeViewItemAutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(oldContainer) as TreeViewItemAutomationPeer;
                    if (peer != null) 
                        peer.RaiseAutomationSelectionEvent(AutomationEvents.SelectionItemPatternOnElementRemovedFromSelection); 
                }
 
                RoutedPropertyChangedEventArgs<object> e = new RoutedPropertyChangedEventArgs<object>(oldValue, newValue, SelectedItemChangedEvent);
                OnSelectedItemChanged(e);
            }
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:80,代码来源:TreeView.cs


注:本文中的System.Windows.Controls.TreeViewItem.UpdateContainsSelection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。