1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Internal.PropertyEditing.Editors
7 using System.Collections.Generic;
8 using System.Diagnostics;
9 using System.Globalization;
11 using System.Windows.Data;
13 using System.Activities.Presentation.PropertyEditing;
14 using System.Activities.Presentation;
16 using System.Activities.Presentation.Internal.PropertyEditing.Model;
17 using System.Activities.Presentation.Internal.Properties;
20 // ValueConverter that takes an instance of PropertyValue and returns a display name for
21 // it. The returned name consists of the value Type name as well as its x:Name property
24 internal class PropertyValueToDisplayNameConverter : IValueConverter
27 private static PropertyValueToDisplayNameConverter _instance;
30 // Static instance accessor for all non-XAML related conversion needs
32 public static PropertyValueToDisplayNameConverter Instance
35 if (_instance == null)
37 _instance = new PropertyValueToDisplayNameConverter();
44 // Converts an instance of PropertyValue to its appropriate display name
45 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
48 if (typeof(string).IsAssignableFrom(targetType))
51 PropertyValue propertyValue = value as PropertyValue;
52 if (propertyValue != null)
55 ModelPropertyEntryBase propertyEntry = propertyValue.ParentProperty as ModelPropertyEntryBase;
57 // Figure out the value type name
58 string valueTypeName = string.Empty;
59 if (propertyEntry != null)
61 valueTypeName = propertyEntry.CommonValueType == null ? string.Empty : propertyEntry.CommonValueType.Name;
65 Debug.Fail("PropertyValueToDisplayNameConverter is being used for something other than ModelPropertyValues. Re-evaluate the correctness of its logic.");
68 object rawPropertyValue = propertyValue.Value;
69 if (rawPropertyValue != null)
71 valueTypeName = rawPropertyValue.GetType().Name;
75 // See if there is a regular name
76 string propertyName = ModelUtilities.GetPropertyName(propertyValue);
78 if (string.IsNullOrEmpty(propertyName))
83 Resources.PropertyEditing_CollectionItemDisplayFormatType,
91 Resources.PropertyEditing_CollectionItemDisplayFormatTypeAndName,
101 // This class is only a one-way converter
102 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
104 throw FxTrace.Exception.AsError(new NotImplementedException());