1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Model
8 using System.Collections.Generic;
11 using System.Activities.Presentation.Model;
13 using System.Diagnostics.CodeAnalysis;
15 public abstract class AttachedProperty
17 Type ownerType = typeof(object);
19 [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "By design.")]
20 public abstract Type Type
25 public abstract bool IsReadOnly
30 public bool IsBrowsable
36 internal bool IsVisibleToModelItem
51 return this.ownerType;
55 this.ownerType = value;
59 public abstract object GetValue(ModelItem modelItem);
60 public abstract void SetValue(ModelItem modelItem, object value);
61 public abstract void ResetValue(ModelItem modelItem);
63 public void NotifyPropertyChanged(ModelItem modelItem)
65 if (null != modelItem)
67 ((IModelTreeItem)modelItem).OnPropertyChanged(this.Name);
73 public class AttachedProperty<T> : AttachedProperty
75 [Fx.Tag.KnownXamlExternal]
76 public Func<ModelItem, T> Getter
81 [Fx.Tag.KnownXamlExternal]
82 public Action<ModelItem, T> Setter
87 public override Type Type
89 get { return typeof(T); }
92 public override bool IsReadOnly
94 get { return (this.Setter == null); }
97 public override object GetValue(ModelItem modelItem)
99 return this.Getter(modelItem);
102 public override void SetValue(ModelItem modelItem, object Value)
106 throw FxTrace.Exception.AsError(new InvalidOperationException(SR.PropertyIsReadOnly));
108 this.Setter(modelItem, (T)Value);
109 this.NotifyPropertyChanged(modelItem);
112 public override void ResetValue(ModelItem modelItem)
114 SetValue(modelItem, default(T));