1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing
6 using System.Diagnostics.CodeAnalysis;
9 using System.Activities.Presentation.PropertyEditing;
11 using Blend = System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector;
12 using System.Activities.Presentation.Internal.PropertyEditing.Selection;
13 using System.Activities.Presentation.Internal.PropertyEditing.State;
16 // Container for PropertyContainers - fancy wrapper for ItemsControl that eliminates the need
17 // for intermediate ContentControls.
19 // This class is referenced from XAML
21 [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
22 internal class CiderStandardCategoryLayout : Blend.StandardCategoryLayout
25 protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
27 base.PrepareContainerForItemOverride(element, item);
31 PropertyEntry property = ((PropertyContainer)element).PropertyEntry;
35 // Make each PropertyContainer its own selection stop
36 PropertySelection.SetSelectionStop(element, new PropertySelectionStop(property));
39 PropertyContainer container = element as PropertyContainer;
40 if (container != null)
42 container.Loaded += new RoutedEventHandler(OnPropertyContainerLoaded);
47 private void OnPropertyContainerLoaded(object sender, RoutedEventArgs e)
49 PropertyContainer container = sender as PropertyContainer;
50 if (container != null)
53 // When each PropertyContainer gets loaded, restore its ActiveEditMode
54 // based on stored state
56 container.ActiveEditMode = PropertyActiveEditModeStateContainer.Instance.GetActiveEditMode(container.PropertyEntry);
58 // HACK: Here, we would want to hook into the ActiveEditModeChanged
59 // event to store (and restore) the correct expaded state to each
60 // value editor across domain reloads. However, we already shipped
61 // System.Activities.Presentation.dll which contains the PropertyContainer
62 // class and it's dangerous to add new events to this assembly at this
63 // point. Once we refactor MWD, we need to add this new event and
64 // simplify this code. In the meanwhile, we can cheat and accomplish
65 // the same effect by listening to SizeChanged event, which _will_
66 // change when the expanded value editor is pinned down. It will also
67 // change at other times (user-triggered resize events, etc.), but
68 // it shouldn't cause any noticeable perf degradation.
70 container.SizeChanged += new SizeChangedEventHandler(OnPropertyContainerSizeChanged);
71 container.Unloaded += new RoutedEventHandler(OnPropertyContainerUnloaded);
75 // When the size of each PropertyContainer changes, assume that ActiveEditMode
76 // may have been changed and record its current state
78 private void OnPropertyContainerSizeChanged(object sender, SizeChangedEventArgs e)
80 PropertyContainer container = sender as PropertyContainer;
81 if (container != null && container.IsLoaded)
83 PropertyActiveEditModeStateContainer.Instance.StoreActiveEditMode(container.PropertyEntry, container.ActiveEditMode);
87 // When each PropertyContainer gets unloaded, stop listening to all events so
88 // that it can be garbage collected
90 private void OnPropertyContainerUnloaded(object sender, RoutedEventArgs e)
92 PropertyContainer container = sender as PropertyContainer;
94 if (container != null)
96 container.SizeChanged -= new SizeChangedEventHandler(OnPropertyContainerSizeChanged);
97 container.Loaded -= new RoutedEventHandler(OnPropertyContainerLoaded);
98 container.Unloaded -= new RoutedEventHandler(OnPropertyContainerUnloaded);