// Set the expansion state on the CategoryContainer based on an existing container // or a cached value for the contained category protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { CiderCategoryContainer container = element as CiderCategoryContainer; CategoryEntry category = item as CategoryEntry; if (container != null && category != null) { // Ideally, we would want to initalize the expansion state here. However, // in collection editor, Blend messes around with the expansion state _after_ // the call to this method, which breaks our ability to remember which categories // were open and which were closed. So, we set the state here (because Blend's // search logic relies on it to be set by this point) and _reset_ it in the Loaded // event handler. // Look into stored state CategoryState state = _categoryStates.GetCategoryState(category.CategoryName); container.Expanded = state.CategoryExpanded; container.AdvancedSectionPinned = state.AdvancedSectionExpanded; // Hook into other event handlers that we care about (including the Loaded event) container.Loaded += new RoutedEventHandler(OnContainerLoaded); container.Unloaded += new RoutedEventHandler(OnContainerUnloaded); if (ContainerGenerated != null) { ContainerGenerated(this, new ContainerGeneratedEventArgs(container)); } } else { Debug.Fail("CategoryList should only be populated with CategoryEntries."); } base.PrepareContainerForItemOverride(element, item); }
public ContainerGeneratedEventArgs(CiderCategoryContainer container) { if (container == null) { throw FxTrace.Exception.ArgumentNull("container"); } _container = container; }
// <summary> // Looks for and returns CategoryContainer for the specified CategoryEntry. Returns null if not // found. // </summary> // <param name="category">CategoryEntry to look for.</param> // <returns>Corresponding CategoryContainer if found, null otherwise.</returns> internal CategoryContainer FindCategoryEntryVisual(CategoryEntry category) { if (category == null) { return(null); } CiderCategoryContainer categoryContainer = this.ItemContainerGenerator.ContainerFromItem(category) as CiderCategoryContainer; return(categoryContainer); }
private static object CoerceIsEmpty(DependencyObject obj, object value) { CiderCategoryContainer theThis = obj as CiderCategoryContainer; if (theThis == null) { return(value); } return(theThis.BasicCategoryEditors.Count == 0 && theThis.UnconsumedBasicProperties.Count == 0 && theThis.AdvancedCategoryEditors.Count == 0 && theThis.UnconsumedAdvancedProperties.Count == 0); }
// Visual Lookup Helpers // <summary> // Looks for and returns the PropertyContainer used to represent the specified PropertyEntry. Returns // null if not found. // </summary> // <param name="property">PropertyEntry to look up</param> // <param name="parentCategory">Category to examine</param> // <param name="pendingGeneration">Set to true if the specified property exists in a collapsed container // (CategoryContainer or an advanced section). If so, the section is expanded, but the visual does not // exist yet and should be requested later. // </param> // <returns>PropertyContainer for the specified PropertyEntry if found, null otherwise</returns> internal PropertyContainer FindPropertyEntryVisual(PropertyEntry property, CategoryEntry parentCategory, out bool pendingGeneration) { pendingGeneration = false; if (property == null || parentCategory == null) { return(null); } if (property.MatchesFilter == false) { return(null); } CiderCategoryContainer categoryContainer = this.ItemContainerGenerator.ContainerFromItem(parentCategory) as CiderCategoryContainer; if (categoryContainer == null) { return(null); } // Expand the parent category, if it isn't already if (!categoryContainer.Expanded) { categoryContainer.Expanded = true; pendingGeneration = true; } // Expand the parent advanced section, if any and if it isn't already if (property.IsAdvanced && !categoryContainer.AdvancedSectionPinned) { categoryContainer.AdvancedSectionPinned = true; pendingGeneration = true; } bool pendingGenerationTemp; PropertyContainer propertyContainer = categoryContainer.ContainerFromProperty(property, out pendingGenerationTemp); pendingGeneration |= pendingGenerationTemp; if (propertyContainer != null) { pendingGeneration = false; } return(propertyContainer); }
private void OnContainerUnloaded(object sender, RoutedEventArgs e) { CiderCategoryContainer container = sender as CiderCategoryContainer; if (container != null) { // Unhook from any events that we used to care about container.ExpandedChanged -= new EventHandler(OnContainerExpandedChanged); container.AdvancedSectionPinnedChanged -= new EventHandler(OnAdvancedSectionPinnedChanged); container.Loaded -= new RoutedEventHandler(OnContainerLoaded); container.Unloaded -= new RoutedEventHandler(OnContainerUnloaded); } else { Debug.Fail("Couldn't clean up event binding and store container state."); } }
// <summary> // Looks for and returns the UIElement used to represent the specified CategoryEditor. Returns // null if not found. // </summary> // <param name="editor">CategoryEditor to look for.</param> // <param name="category">Category to look in.</param> // <param name="pendingGeneration">Set to true if the specified editor exists in a collapsed container // (CategoryContainer or an advanced section). If so, the section is expanded, but the visual does not // exist yet and should be requested later.</param> // <returns>UIElement for the specified CategoryEditor if found, null otherwise</returns> internal UIElement FindCategoryEditorVisual(CategoryEditor editor, ModelCategoryEntry category, out bool pendingGeneration) { pendingGeneration = false; if (editor == null || category == null) { return(null); } UIElement editorVisual = null; CiderCategoryContainer categoryContainer = this.ItemContainerGenerator.ContainerFromItem(category) as CiderCategoryContainer; if (categoryContainer == null) { return(null); } // Expand the parent category, if it isn't already if (!categoryContainer.Expanded) { categoryContainer.Expanded = true; pendingGeneration = true; } // Expand the parent advanced section, if any and if it isn't already if (!categoryContainer.AdvancedSectionPinned && ExtensibilityAccessor.GetIsAdvanced(editor)) { categoryContainer.AdvancedSectionPinned = true; pendingGeneration = true; } bool pendingGenerationTemp; editorVisual = categoryContainer.ContainerFromEditor(editor, out pendingGenerationTemp); pendingGeneration |= pendingGenerationTemp; if (editorVisual != null) { pendingGeneration = false; } return(editorVisual); }
private void OnAdvancedSectionPinnedChanged(object sender, EventArgs e) { // If we are in "Filter-applied" mode, don't store the expansion state, since applying // the filter automatically expands everything that matches that filter if (_currentFilter != null && !_currentFilter.IsEmpty) { return; } CiderCategoryContainer container = sender as CiderCategoryContainer; if (container != null) { CategoryEntry category = container.Category; if (category != null) { CategoryState state = _categoryStates.GetCategoryState(container.Category.CategoryName); state.AdvancedSectionExpanded = container.AdvancedSectionPinned; } } }
// Re-initialize the expansion state here and hook into the ExpandedChanged and // AdvancedSectionPinnedChanged events, because by now Blend may have ----ed those // two values up (see comment in PrepareContainerForItemOverride() ) private void OnContainerLoaded(object sender, RoutedEventArgs e) { CiderCategoryContainer container = sender as CiderCategoryContainer; if (container != null) { CategoryEntry category = container.Category; if (category != null) { // Look into stored state CategoryState state = _categoryStates.GetCategoryState(category.CategoryName); container.Expanded = state.CategoryExpanded; container.AdvancedSectionPinned = state.AdvancedSectionExpanded; // Hook into these events here, because Blend won't mess the state up at this point container.ExpandedChanged += new EventHandler(OnContainerExpandedChanged); container.AdvancedSectionPinnedChanged += new EventHandler(OnAdvancedSectionPinnedChanged); } } else { Debug.Fail("CategoryList expects the individual items to be CiderCategoryContainers"); } }