1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Converters
7 using System.Diagnostics;
8 using System.Globalization;
9 using System.Windows.Data;
10 using System.Activities.Presentation.Model;
11 using System.Activities.Presentation.Internal.PropertyEditing.Model;
13 //This value converter is used in propertygrid scenarios to convert an object into a ModelItem.
14 //It converts from ModelPropertyEntry to ModelItem that owns the property
15 //The first binding is a two way binding with the PropertyValue object
16 //The second binding is a one way binding with the ModelPropertyEntry.
17 public class ObjectToModelValueConverter : IMultiValueConverter
20 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
22 ModelItem convertedValue = null;
23 if (values[1] != null)
25 ModelPropertyEntry modelPropertyEntry = values[1] as ModelPropertyEntry;
26 if (modelPropertyEntry != null)
28 ModelProperty property = modelPropertyEntry.FirstModelProperty;
31 convertedValue = property.Value;
35 return convertedValue;
38 public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
40 object[] returnValue = new object[] { null };
43 returnValue[0] = ((ModelItem)value).GetCurrentValue();