1 //----------------------------------------------------------------
2 // <copyright company="Microsoft Corporation">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //----------------------------------------------------------------
7 namespace System.Activities.Presentation.Annotations
9 using System.Activities.Presentation.Model;
10 using System.Windows.Controls;
11 using System.Windows.Documents;
14 internal class WorkflowAnnotationAdornerService : AnnotationAdornerService
16 private ScrollViewer scrollViewer;
19 internal WorkflowAnnotationAdornerService()
23 public override void Show(AnnotationAdorner adorner)
30 AnnotationAdorner.SetAnchor(adorner, AdornerLocation.None);
31 adorner.ScrollViewer = this.scrollViewer;
33 AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adorner.AdornedElement);
34 if (adornerLayer != null)
36 adornerLayer.Add(adorner);
42 public override void Hide(AnnotationAdorner adorner)
49 AnnotationAdorner.SetAnchor(adorner, AdornerLocation.None);
51 AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adorner.AdornedElement);
52 if (adornerLayer != null)
54 adornerLayer.Remove(adorner);
60 internal void Initialize(EditingContext editingContext, ScrollViewer scrollViewer)
62 this.scrollViewer = scrollViewer;
63 this.enabled = editingContext.Services.GetService<DesignerConfigurationService>().AnnotationEnabled;
70 AttachedPropertiesService attachedPropertiesService = editingContext.Services.GetService<AttachedPropertiesService>();
71 AttachedProperty<string> attachedProperty = new AttachedProperty<string>
74 IsVisibleToModelItem = true,
75 Name = Annotation.AnnotationTextPropertyName,
76 OwnerType = typeof(object),
77 Getter = (modelItem) =>
79 string annotation = null;
80 AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out annotation);
83 Setter = (modelItem, value) =>
85 string oldValue = null;
86 AttachablePropertyServices.TryGetProperty<string>(modelItem.GetCurrentValue(), Annotation.AnnotationTextProperty, out oldValue);
87 if (oldValue == value)
92 ModelTreeManager treeManager = modelItem.GetEditingContext().Services.GetService<ModelTreeManager>();
94 AttachablePropertyChange change = new AttachablePropertyChange()
97 AttachablePropertyIdentifier = Annotation.AnnotationTextProperty,
100 PropertyName = Annotation.AnnotationTextPropertyName
103 treeManager.AddToCurrentEditingScope(change);
107 attachedPropertiesService.AddProperty(attachedProperty);