1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.ServiceModel.Activities.Presentation
7 using System.Activities.Core.Presentation.Themes;
8 using System.Activities.Presentation;
9 using System.Activities.Presentation.Converters;
10 using System.Activities.Presentation.Model;
11 using System.Activities.Presentation.PropertyEditing;
12 using System.Activities.Presentation.View;
15 using System.Windows.Controls;
17 sealed class CorrelatesOnValueEditor : DialogPropertyValueEditor
19 public CorrelatesOnValueEditor()
21 this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_InlineTemplate");
24 public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
26 ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
28 ModelItem modelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null);
29 EditingContext context = modelItem.GetEditingContext();
31 this.ShowDialog(modelItem, context);
34 public void ShowDialog(ModelItem activity, EditingContext context)
36 Fx.Assert(activity != null, "Activity model item shouldn't be null!");
37 Fx.Assert(context != null, "EditingContext shouldn't be null!");
40 string bookmarkTitle = (string)this.InlineEditorTemplate.Resources["bookmarkTitle"];
42 UndoEngine undoEngine = context.Services.GetService<UndoEngine>();
43 Fx.Assert(null != undoEngine, "UndoEngine should be available");
45 using (EditingScope scope = context.Services.GetRequiredService<ModelTreeManager>().CreateEditingScope(bookmarkTitle, true))
47 if ((new EditorWindow(activity, context)).ShowOkCancel())
54 sealed class EditorWindow : WorkflowElementDialog
56 public EditorWindow(ModelItem activity, EditingContext context)
58 this.ModelItem = activity;
59 this.Context = context;
60 this.Owner = activity.View;
61 this.EnableMaximizeButton = false;
62 this.EnableMinimizeButton = false;
65 this.WindowResizeMode = ResizeMode.CanResize;
66 this.WindowSizeToContent = SizeToContent.Manual;
67 var template = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("CorrelatesOnDesigner_DialogTemplate");
69 var presenter = new ContentPresenter()
72 ContentTemplate = template
74 this.Title = (string)template.Resources["controlTitle"];
75 this.Content = presenter;
76 this.HelpKeyword = HelpKeywords.CorrelatesOnDefinitionDialog;
79 protected override void OnWorkflowElementDialogClosed(bool? dialogResult)
81 if (dialogResult.HasValue && dialogResult.Value)
83 var correlatesOnProperty = this.ModelItem.Properties["CorrelatesOn"];
85 if (correlatesOnProperty.IsSet && 0 == correlatesOnProperty.Dictionary.Count)
87 correlatesOnProperty.ClearValue();