1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Editors
7 using System.Diagnostics.CodeAnalysis;
9 using System.Windows.Controls;
10 using System.Windows.Media;
12 using System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.ValueEditors;
15 // DataTemplateSelector we use in some instances of ChoiceEditor (namely sub-property editor)
16 // to detect whether the given item is being displayed in the popup or as an inline item.
17 // Based on that determination, it returns the appropriate DataTemplate. This is a work-around
18 // for the problem where we can't determine which NewItemTypeFactory instantiated a given instance.
19 // Hence, we show the instance Type inline the ComboBox and the factory DisplayName in the drop-down.
20 // Ideally, we would want to use a different control to handle this scenario.
22 internal class QuickItemTemplateSelector : DataTemplateSelector
25 private DataTemplate _popupTemplate;
26 private DataTemplate _inlineTemplate;
28 public DataTemplate PopupTemplate
30 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
31 get { return _popupTemplate; }
32 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 set { _popupTemplate = value; }
36 public DataTemplate InlineTemplate
38 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
39 get { return _inlineTemplate; }
40 [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
41 set { _inlineTemplate = value; }
44 public override DataTemplate SelectTemplate(object item, DependencyObject container)
46 return HasChoiceEditorParent(container) ? _inlineTemplate : _popupTemplate;
49 private bool HasChoiceEditorParent(DependencyObject element)
51 while (element != null)
53 element = VisualTreeHelper.GetParent(element);
54 if (element != null && typeof(ChoiceEditor).IsAssignableFrom(element.GetType()))