/// <summary> /// /// </summary> /// <param name="ToEvaluate"></param> public static void ClearSelection(this ItemsControl ToEvaluate) { if (ToEvaluate is ListBox) { (ToEvaluate as ListBox).SelectedItems.Clear(); } else if (ToEvaluate is DataGrid) { (ToEvaluate as DataGrid).SelectedItems.Clear(); } else if (ToEvaluate is TreeView) { var TreeView = ToEvaluate.As <TreeView>(); var Item = TreeView.ItemContainerGenerator.ContainerFromItem(TreeView.SelectedItem); if (Item != null) { Item.As <TreeViewItem>().IsSelected = false; } } else if (ToEvaluate is TreeView) { ToEvaluate.As <TreeView>().SelectNone(); } }