1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation
7 using System.Windows.Controls;
8 using System.Activities.Presentation.Model;
9 using System.Activities.Presentation.Hosting;
12 [Fx.Tag.XamlVisible(false)]
13 public class WorkflowElementDialog : ContentControl
15 public static readonly DependencyProperty ModelItemProperty =
16 DependencyProperty.Register("ModelItem",
18 typeof(WorkflowElementDialog),
19 new PropertyMetadata(OnModelItemChanged));
21 public static readonly DependencyProperty TitleProperty =
22 DependencyProperty.Register("Title",
24 typeof(WorkflowElementDialog));
26 public static readonly DependencyProperty ContextProperty =
27 DependencyProperty.Register("Context",
28 typeof(EditingContext),
29 typeof(WorkflowElementDialog));
31 public static readonly DependencyProperty WindowResizeModeProperty =
32 DependencyProperty.Register("WindowResizeMode",
34 typeof(WorkflowElementDialog),
35 new UIPropertyMetadata(ResizeMode.CanResize));
37 public static readonly DependencyProperty WindowSizeToContentProperty =
38 DependencyProperty.Register("WindowSizeToContent",
39 typeof(SizeToContent),
40 typeof(WorkflowElementDialog),
41 new UIPropertyMetadata(SizeToContent.WidthAndHeight));
43 protected WorkflowElementDialog()
47 public ModelItem ModelItem
49 get { return (ModelItem)GetValue(ModelItemProperty); }
50 set { SetValue(ModelItemProperty, value); }
55 get { return (string)GetValue(TitleProperty); }
56 set { SetValue(TitleProperty, value); }
59 public EditingContext Context
61 get { return (EditingContext)GetValue(ContextProperty); }
62 set { SetValue(ContextProperty, value); }
65 public DependencyObject Owner
71 public ResizeMode WindowResizeMode
73 get { return (ResizeMode)GetValue(WindowResizeModeProperty); }
74 set { SetValue(WindowResizeModeProperty, value); }
77 public SizeToContent WindowSizeToContent
79 get { return (SizeToContent)GetValue(WindowSizeToContentProperty); }
80 set { SetValue(WindowSizeToContentProperty, value); }
83 public bool EnableMinimizeButton
89 public bool EnableMaximizeButton
95 public string HelpKeyword
101 internal Func<bool> OnOk
112 public bool ShowOkCancel()
114 bool? result = Show(true);
115 return result.HasValue && result.Value;
118 internal void CloseDialog(bool commitChanges)
120 this.Window.DialogResult = commitChanges;
123 internal WorkflowElementDialogWindow Window
129 bool? Show(bool okCancel)
131 WorkflowElementDialogWindow wnd = new WorkflowElementDialogWindow(this, okCancel, this.EnableMinimizeButton, this.EnableMaximizeButton, this.OnOk)
135 if (null != this.Context)
137 WindowHelperService srv = this.Context.Services.GetService<WindowHelperService>();
140 srv.TrySetWindowOwner(this.Owner, wnd);
143 wnd.Closed += (s, e) => { this.OnWorkflowElementDialogClosed(((Window)s).DialogResult); };
144 return wnd.ShowDialog();
147 protected override void OnInitialized(EventArgs e)
149 base.OnInitialized(e);
150 // This is necessary for WPF data bindings to work.
151 // It needs to be done explicitly, probably because
152 // this ContentControl doesn't define its own
153 // Template.VisualTree (maybe it should).
154 this.DataContext = this;
157 protected void EnableOk(bool enabled)
159 if (this.Window != null)
161 this.Window.okButton.IsEnabled = enabled;
165 protected virtual void OnModelItemChanged(object newItem)
169 protected virtual void OnWorkflowElementDialogClosed(bool? dialogResult)
173 static void OnModelItemChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
175 WorkflowElementDialog dialog = (WorkflowElementDialog)dependencyObject;
176 dialog.OnModelItemChanged(e.NewValue);