1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Converters
7 using System.Activities.Presentation.Internal.PropertyEditing.Model;
8 using System.Activities.Presentation.Model;
9 using System.Globalization;
11 using System.ServiceModel.Activities;
12 using System.Windows.Data;
14 // This type converter converts from ModelPropertyEntry to ModelItem that owns the property
15 public class ModelPropertyEntryToOwnerActivityConverter : IValueConverter
17 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
19 //converter can be parametrized - by default, always return parent model item of type Activity or WorkflowService,
20 //but if false is passed in - simply return first parent
21 bool returnParentWorkflowElement = true;
22 if (null != parameter && parameter is bool)
24 returnParentWorkflowElement = (bool)parameter;
27 return ModelPropertyEntryToOwnerActivityConverter.Convert(value as ModelPropertyEntry, returnParentWorkflowElement);
30 internal static ModelItem Convert(ModelPropertyEntry modelPropertyEntry, bool returnParentActivity)
32 ModelItem convertedValue = null;
33 if (modelPropertyEntry != null)
35 ModelProperty property = modelPropertyEntry.FirstModelProperty;
38 convertedValue = property.Parent;
39 if (returnParentActivity)
41 while (convertedValue != null)
43 Type itemType = convertedValue.ItemType;
44 if (typeof(Activity).IsAssignableFrom(itemType) || typeof(WorkflowService).IsAssignableFrom(itemType))
49 convertedValue = convertedValue.Parent;
55 return convertedValue;
58 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
60 Fx.Assert("this value converter only works on the forward direction");