/// <summary> /// Selects a tree view item based on an item. /// </summary> /// <param name="firstLevelItem">Item that correlates to a the TreeViewItem.</param> private void SelectTreeViewItemFor(SampleTreeItem firstLevelItem) { SampleSelection.Loaded += (s, args) => { ((TreeViewItem)SampleSelection.ItemContainerGenerator.ContainerFromItem(firstLevelItem)).IsSelected = true; }; }
/// <summary> /// Selects a tree view item based on an item. /// </summary> /// <param name="firstLevelItem">Item that correlates to a the first level TreeViewItem.</param> /// <param name="secondLevelItem">Item that correlates to a the second level TreeViewItem.</param> private void SelectTreeViewItemFor(SampleTreeItem firstLevelItem, SampleTreeItem secondLevelItem) { SampleSelection.Loaded += (s, args) => { TreeViewItem firstLevelTreeViewItem = (TreeViewItem) SampleSelection.ItemContainerGenerator.ContainerFromItem(firstLevelItem); TreeViewItem secondLevelTreeViewItem = (TreeViewItem) firstLevelTreeViewItem.ItemContainerGenerator.ContainerFromItem(secondLevelItem); secondLevelTreeViewItem.IsSelected = true; // check if 3rd level deep link path has a correlating TabItem if (!string.IsNullOrEmpty(GetPathForLevel(2))) { TabItem tabItemToSelect = SamplesTab.Items.OfType<TabItem>().SingleOrDefault( t => ((SampleBrowserItem) t.Header).Name == GetPathForLevel(2)); if (tabItemToSelect != null) { tabItemToSelect.IsSelected = true; } } }; }