1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Core.Presentation
7 using System.Activities.Presentation;
8 using System.Activities.Presentation.Annotations;
9 using System.Activities.Presentation.Metadata;
10 using System.Activities.Presentation.View;
11 using System.Activities.Presentation.View.OutlineView;
12 using System.Activities.Statements;
13 using System.ComponentModel;
15 using System.Windows.Automation.Peers;
16 using System.Windows.Controls;
17 using System.Windows.Data;
18 using System.Windows.Documents;
19 using System.Windows.Media;
20 using Microsoft.Activities.Presentation;
22 partial class FlowDecisionDesigner
24 public static readonly DependencyProperty ExpressionButtonVisibilityProperty =
25 DependencyProperty.Register("ExpressionButtonVisibility", typeof(Visibility), typeof(FlowDecisionDesigner));
27 public static readonly DependencyProperty ExpressionButtonColorProperty =
28 DependencyProperty.Register("ExpressionButtonColor", typeof(Brush), typeof(FlowDecisionDesigner));
30 static readonly DependencyProperty ShowAllConditionsProperty =
31 DependencyProperty.Register("ShowAllConditions", typeof(bool), typeof(FlowDecisionDesigner),
32 new UIPropertyMetadata(new PropertyChangedCallback(OnShowAllConditionsChanged)));
35 bool expressionShown = false;
37 private AnnotationManager annotationManager;
39 public FlowDecisionDesigner()
41 InitializeComponent();
42 this.Loaded += (sender, e) =>
44 //UnRegistering because of 137896: Inside tab control multiple Loaded events happen without an Unloaded event.
45 this.ModelItem.PropertyChanged -= OnModelItemPropertyChanged;
46 this.ModelItem.PropertyChanged += OnModelItemPropertyChanged;
47 OnModelItemPropertyChanged(this.ModelItem, new PropertyChangedEventArgs("Condition"));
51 if (this.Context.Services.GetService<DesignerConfigurationService>().TargetFrameworkName.IsLessThan45())
53 this.displayNameTextBox.IsReadOnly = true;
56 this.annotationManager.Initialize();
58 this.Unloaded += (sender, e) =>
60 this.ModelItem.PropertyChanged -= OnModelItemPropertyChanged;
61 this.annotationManager.Uninitialize();
63 this.MouseEnter += (sender, e) =>
67 this.MouseLeave += (sender, e) =>
72 this.InitializeAnnotation();
75 private void InitializeAnnotation()
77 this.annotationManager = new AnnotationManager(this);
78 this.annotationManager.AnnotationVisualProvider = new FlowDecisionDesignerAnnotationVisualProvider(this);
83 Binding showAllConditionsBinding = new Binding();
84 showAllConditionsBinding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FlowchartDesigner), 1);
85 showAllConditionsBinding.Path = new PropertyPath(FlowchartDesigner.ShowAllConditionsProperty);
86 showAllConditionsBinding.Mode = BindingMode.OneWay;
88 BindingOperations.SetBinding(this, FlowDecisionDesigner.ShowAllConditionsProperty, showAllConditionsBinding);
91 public Visibility ExpressionButtonVisibility
93 get { return (Visibility)GetValue(ExpressionButtonVisibilityProperty); }
94 set { SetValue(ExpressionButtonVisibilityProperty, value); }
97 public Brush ExpressionButtonColor
99 get { return (Brush)GetValue(ExpressionButtonColorProperty); }
100 set { SetValue(ExpressionButtonColorProperty, value); }
103 public bool ExpressionShown
105 get { return this.expressionShown; }
108 public static void RegisterMetadata(AttributeTableBuilder builder)
110 Type type = typeof(FlowDecision);
111 builder.AddCustomAttributes(type, new DesignerAttribute(typeof(FlowDecisionDesigner)));
112 builder.AddCustomAttributes(type, type.GetProperty("True"), BrowsableAttribute.No);
113 builder.AddCustomAttributes(type, type.GetProperty("False"), BrowsableAttribute.No);
114 builder.AddCustomAttributes(type, type.GetProperty("Condition"), new HidePropertyInOutlineViewAttribute());
115 builder.AddCustomAttributes(type, new FeatureAttribute(typeof(FlowDecisionLabelFeature)));
116 builder.AddCustomAttributes(type, new ActivityDesignerOptionsAttribute
118 AllowDrillIn = false,
119 OutlineViewIconProvider = (modelItem) =>
121 if (modelItem != null)
123 ResourceDictionary icons = EditorResources.GetIcons();
124 if (icons.Contains("FlowDecisionIcon") && icons["FlowDecisionIcon"] is DrawingBrush)
126 return (DrawingBrush)icons["FlowDecisionIcon"];
135 protected override AutomationPeer OnCreateAutomationPeer()
137 return new FlowchartExpressionAutomationPeer(this, base.OnCreateAutomationPeer());
141 void OnExpressionButtonClicked(object sender, RoutedEventArgs e)
143 this.isPinned = !this.isPinned;
147 void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e)
149 if (e.PropertyName == "Condition")
157 Activity expressionActivity = this.ModelItem.Properties["Condition"].ComputedValue as Activity;
158 string expressionString = ExpressionHelper.GetExpressionString(expressionActivity, this.ModelItem);
159 bool expressionSpecified = !string.IsNullOrEmpty(expressionString);
160 if (!expressionSpecified)
162 this.isPinned = false;
165 this.ExpressionButtonVisibility = expressionSpecified ? Visibility.Visible : Visibility.Collapsed;
169 this.ExpressionButtonColor = WorkflowDesignerColors.FlowchartExpressionButtonPressedBrush;
171 else if (this.IsMouseOver)
173 this.ExpressionButtonColor = WorkflowDesignerColors.FlowchartExpressionButtonMouseOverBrush;
177 this.ExpressionButtonColor = WorkflowDesignerColors.FlowchartExpressionButtonBrush;
179 expressionShown = false;
180 AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
181 if (adornerLayer != null)
183 Adorner[] adorners = adornerLayer.GetAdorners(this);
184 if (adorners != null)
186 foreach (Adorner adorner in adorners)
188 if (adorner is FlowchartExpressionAdorner)
190 adornerLayer.Remove(adorner);
194 if ((this.IsMouseOver && expressionSpecified) || this.isPinned)
196 expressionShown = true;
197 adornerLayer.Add(new FlowchartExpressionAdorner(this));
202 static void OnShowAllConditionsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
204 if (e.NewValue != DependencyProperty.UnsetValue)
206 FlowDecisionDesigner designer = obj as FlowDecisionDesigner;
207 designer.OnShowAllConditionsChanged((bool)e.NewValue);
211 void OnShowAllConditionsChanged(bool isOpen)
213 this.isPinned = isOpen;
217 protected internal override void OnEditAnnotation()
219 this.annotationManager.OnEditAnnotation();
222 private class FlowDecisionDesignerAnnotationVisualProvider : IAnnotationVisualProvider
224 private FlowDecisionDesigner designer;
225 private IAnnotationIndicator indicator;
226 private IFloatingAnnotation floatingAnnotation;
227 private IDockedAnnotation dockedAnnotation;
229 public FlowDecisionDesignerAnnotationVisualProvider(FlowDecisionDesigner designer)
231 this.designer = designer;
234 public IAnnotationIndicator GetAnnotationIndicator()
236 if (this.indicator == null)
238 this.indicator = new UIElementToAnnotationIndicatorAdapter(this.designer.defaultAnnotationIndicator);
241 return this.indicator;
244 public IFloatingAnnotation GetFloatingAnnotation()
246 if (this.floatingAnnotation == null)
248 this.floatingAnnotation = new FloatingAnnotationView();
251 return this.floatingAnnotation;
254 public IDockedAnnotation GetDockedAnnotation()
256 if (this.dockedAnnotation == null)
258 DockedAnnotationView view = new DockedAnnotationView();
259 Binding binding = new Binding("ModelItem.AnnotationText");
260 view.SetBinding(DockedAnnotationView.AnnotationTextProperty, binding);
261 view.Visibility = Visibility.Collapsed;
262 Grid.SetRow(view, 0);
264 this.dockedAnnotation = view;
265 this.designer.rootGrid.Children.Insert(0, view);
268 return this.dockedAnnotation;