private static void OnSelectedWebElementChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var model = e.NewValue as WebElementInfoViewModel; if (model != null) { var tree = (sender as WebElementsTreeUserControl).WebElementsTreeView; var tvi = SaKiWpfHelper.FindTreeViewItemForObject(tree, model); if (tvi == null) { SaKiWpfHelper.ExpandCollapseItemsControl(tree); tvi = SaKiWpfHelper.FindTreeViewItemForObject(tree, model); } if (tvi != null) { ExpandElementTree(model, tree); tvi.SetValue(TreeViewItem.IsSelectedProperty, true); } } else { model = (sender as WebElementsTreeUserControl).WebElementsTreeView.SelectedItem as WebElementInfoViewModel; if (model != null) { var tvi = SaKiWpfHelper.FindTreeViewItemForObject((sender as WebElementsTreeUserControl).WebElementsTreeView, model); if (tvi != null) { tvi.SetValue(TreeViewItem.IsSelectedProperty, false); } } } }
private static void ExpandElementTreeItem(WebElementInfoViewModel model, ItemsControl control) { var tvi = SaKiWpfHelper.FindTreeViewItemForObject(control, model); tvi?.SetValue(TreeViewItem.IsExpandedProperty, true); }