/// <summary> /// Initializes a new instance of the /// <see cref="T:System.Windows.Controls.HeaderedItemsControl" /> class. /// </summary> public HeaderedItemsControl() { DefaultStyleKey = typeof(HeaderedItemsControl); ItemsControlHelper = new ItemsControlHelper(this); }
/// <summary> /// Initializes a new instance of the /// <see cref="T:WinRTXamlToolkit.Controls.TreeView" /> class. /// </summary> public TreeView() { var pcc = new PropertyChangeEventSource<Style>(this, "ItemContainerStyle"); pcc.ValueChanged += OnItemContainerStylePropertyChanged; DefaultStyleKey = typeof(TreeView); ItemsControlHelper = new ItemsControlHelper(this); Interaction = new InteractionHelper(this); }
/// <summary> /// Builds the visual tree for the /// <see cref="T:WinRTXamlToolkit.Controls.TreeView" /> control when a new /// control template is applied. /// </summary> protected override void OnApplyTemplate() { ItemsControlHelper.OnApplyTemplate(); Interaction.OnApplyTemplateBase(); base.OnApplyTemplate(); }
/// <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)); } }