// <summary> // This public method is called when parent creates the CategoryContainerItemAutomationPeer // in the GetChildrenCore, thus clearing off all the event listeners before we add new ones // </summary> public void RemoveFocusEvents() { if (_container != null) { UnHookFocusEvents(VisualTreeUtils.GetNamedChild <Expander>(_container, "PART_AdvancedExpander"), OnIsSelectedValueChanged); } }
// <summary> // This public method is called when parent creates the CategoryContainerItemAutomationPeer // in the GetChildrenCore, thus listening to the changes in the IsSelectedProperty. // </summary> private void AddFocusEvents() { if (_container != null) { HookUpFocusEvents(VisualTreeUtils.GetNamedChild <Expander>(_container, "PART_AdvancedExpander"), OnIsSelectedValueChanged); } }
void OnWindowLoaded(object sender, RoutedEventArgs args) { ContentPresenter presenter = (ContentPresenter)this.Content; PropertyValue propertyValue = (PropertyValue)presenter.Content; Button okButton = (Button)this.FindName("okButton"); ExpressionTextBox etb = VisualTreeUtils.GetNamedChild <ExpressionTextBox>(presenter, "PART_expressionTextBox"); TextBlock hint = VisualTreeUtils.GetNamedChild <TextBlock>(presenter, "PART_hintText"); Fx.Assert(etb != null, "ExpressionTextBox with name 'PART_expressionTextBox' should be in the template!"); Fx.Assert(hint != null, "Hint TextBlock with name 'PART_hintText' should be in the template!"); //bind button with ETB's commit command okButton.Command = DesignerView.CommitCommand; okButton.CommandTarget = etb; etb.Loaded += new RoutedEventHandler(OnExpressionTextBoxLoaded); if (null != etb && null != hint) { IValueConverter typeToStringConverter = (IValueConverter)EditorResources.GetResources()["TypeParameterConverter"]; string hintFormatString = (string)EditorResources.GetResources()["dialogExpressionEditorHintFormatString"]; //convert expression's container type to friendly name (i.e. replace generic '1 with <T>) string friendlyTypeName = (string) typeToStringConverter.Convert(etb.ExpressionType ?? propertyValue.ParentProperty.PropertyType, typeof(string), null, CultureInfo.CurrentCulture); //format editor title to include friendly type name and property name hint.Text = string.Format(CultureInfo.CurrentCulture, hintFormatString, propertyValue.ParentProperty.PropertyName, friendlyTypeName); } }
// 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)); }
// <summary> // Private method to unhook the ValueChanged event. // </summary> // <param name="expander">Expander</param> // <param name="valueChangedEvent">ValueChanged event</param> private static void UnHookFocusEvents(Expander expander, EventHandler valueChangedEvent) { if (expander != null) { FrameworkElement expanderGrid = VisualTreeUtils.GetNamedChild <FrameworkElement>(expander, "PART_AdvancedSection"); if (expanderGrid != null) { DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(PropertySelection.IsSelectedProperty, typeof(Grid)); if (dpd != null) { dpd.RemoveValueChanged(expanderGrid, valueChangedEvent); } } } }
protected override List <AutomationPeer> GetChildrenCore() { if (_children != null) { foreach (AutomationPeer peer in _children) { IAutomationFocusChangedEventSource unhookEventPeer = peer as IAutomationFocusChangedEventSource; if (unhookEventPeer != null) { unhookEventPeer.UnloadEventHook(); } } _children.Clear(); } // See if we have access to the QuickTypes combo box (it may or may not be available) AutomatedChoiceEditor choiceEditor = VisualTreeUtils.GetNamedChild <AutomatedChoiceEditor>(_editor, "PART_ValueEditor"); // If we do, present it as one of our children if (choiceEditor != null) { _children.Add(new HiddenUIElementAutomationPeer(choiceEditor)); } // Add any sub-properties ItemsControl properties = VisualTreeUtils.GetNamedChild <ItemsControl>(_editor, "PART_SubPropertyList"); if (properties != null) { int childCount = properties.Items.Count; for (int i = 0; i < childCount; i++) { PropertyContainer propertyContainer = properties.ItemContainerGenerator.ContainerFromIndex(i) as PropertyContainer; if (propertyContainer != null) { PropertyContainerAutomationPeer peer = new PropertyContainerAutomationPeer(propertyContainer); _children.Add(peer); } } } return(_children); }
protected override List <AutomationPeer> GetChildrenCore() { _children = new List <AutomationPeer>(); if (_container != null) { CategoryContainerAutomationPeer.AddCategoryEditors(_children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_AdvancedCategoryEditors"), Resources.PropertyEditing_AdvancedCategoryEditors); CategoryContainerAutomationPeer.AddCategoryProperties(_children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_AdvancedPropertyList")); } //Add focus events for Subproperty editor foreach (AutomationPeer peer in _children) { PropertyContainerAutomationPeer pcAutomationPeer = peer as PropertyContainerAutomationPeer; if (pcAutomationPeer != null) { pcAutomationPeer.AddFocusEvents(); } } return(_children); }
// Gets the children of the contained CategoryContainer, returning AutomationPeers // for CategoryEditors followed by AutomationPeers for any left-over properties private List <AutomationPeer> GetChildrenCore() { List <AutomationPeer> children = new List <AutomationPeer>(); if (_container != null) { AddCategoryEditors(children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_BasicCategoryEditors"), Resources.PropertyEditing_BasicCategoryEditors); AddCategoryProperties(children, VisualTreeUtils.GetNamedChild <ItemsControl>(_container, "PART_BasicPropertyList")); if (_container.Expanded) { Expander advancedExpander = VisualTreeUtils.GetNamedChild <Expander>(_container, "PART_AdvancedExpander"); if (advancedExpander != null && advancedExpander.Visibility == Visibility.Visible) { children.Add(new AdvancedCategoryContainerAutomationPeer(_container, advancedExpander)); } } } return(children); }