// ISelectionPathInterpreter Members public DependencyObject ResolveSelectionPath(CategoryList root, SelectionPath path, out bool pendingGeneration) { pendingGeneration = false; if (path == null || !string.Equals(PathTypeId, path.PathTypeId)) { Debug.Fail("Invalid SelectionPath specified."); return(null); } if (root == null) { Debug.Fail("No CategoryList specified."); return(null); } string[] pathValues = path.Path.Split(','); string categoryName = PersistedStateUtilities.Unescape(pathValues[0]); bool isAdvanced = pathValues.Length == 2; CategoryEntry category = root.FindCategory(categoryName); if (category == null) { return(null); } DependencyObject categoryVisual = root.FindCategoryEntryVisual(category); if (categoryVisual == null) { return(null); } DependencyObject searchStart; // For basic section, start at the root. // For advanced section, start at the advanced expander. // The next SelectionStop in both cases will be the section header SelectionStop. if (!isAdvanced) { searchStart = categoryVisual; } else { searchStart = VisualTreeUtils.GetNamedChild <FrameworkElement>(categoryVisual, "PART_AdvancedExpander"); } return(PropertySelection.FindNeighborSelectionStop <DependencyObject>(searchStart, SearchDirection.Next)); }
// Called when the UI object representing a SelectionStop gets clicked: // // * If this is a double-click and the SelectionStop can be expanded / collapsed, // expand / collapse the SelectionStop // private static void OnSelectionStopDoubleClickTargetMouseDown(object sender, MouseButtonEventArgs e) { DependencyObject target = e.OriginalSource as DependencyObject; if (target == null) { return; } if (e.ClickCount > 1) { FrameworkElement parentSelectionStopVisual = PropertySelection.FindParentSelectionStop <FrameworkElement>(target); if (parentSelectionStopVisual != null) { ISelectionStop parentSelectionStop = PropertySelection.GetSelectionStop(parentSelectionStopVisual); if (parentSelectionStop != null && parentSelectionStop.IsExpandable) { parentSelectionStop.IsExpanded = !parentSelectionStop.IsExpanded; } } } }
// Helper method that returns false if the given element is a collapsed SelectionStop, // true otherwise. // private static bool IsExpanded(DependencyObject element) { ISelectionStop selectionStop = PropertySelection.GetSelectionStop(element); return(selectionStop == null || selectionStop.IsExpanded); }