void SetItemSelected(SiteItemBase siteItem, bool isSelected) { try { siteItem.Selected = isSelected; var treeViewItem = TreeViewHelper.GetTreeViewItem(siteFiles, siteItem); //uncomment the following line if UI updates are unnecessary treeViewItem.IsSelected = true; const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; var selectMethod = typeof(TreeViewItem).GetMethod("Select", bindingFlags); selectMethod.Invoke(treeViewItem, new object[] { isSelected }); } catch { } }
private void SiteFilesSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) { if (currentlySelectedItem != null) currentlySelectedItem.Selected = false; var siteItem = (SiteItemBase)e.NewValue; if (siteItem == null) { currentlySelectedItem = null; selectedTime = null; return; } siteItem.Selected = true; currentlySelectedItem = siteItem; selectedTime = DateTime.Now; }