1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Model
8 using System.Collections.Generic;
10 using System.Globalization;
12 using System.Activities.Presentation.Services;
14 class PropertyChange : ModelChange
16 public ModelItem Owner { get; set; }
18 public string PropertyName { get; set; }
20 public ModelItem OldValue { get; set; }
22 public ModelItem NewValue { get; set; }
24 public ModelTreeManager ModelTreeManager { get; set; }
26 public override string Description
30 return string.Format(CultureInfo.InvariantCulture, "{0} - {1}", SR.PropertyChangeEditingScopeDescription, this.PropertyName);
34 public override bool Apply()
36 Fx.Assert(this.ModelTreeManager != null, "Modeltreemanager cannot be null");
37 Fx.Assert(this.Owner != null, "Owner modelitem cannot be null");
38 Fx.Assert(!String.IsNullOrEmpty(this.PropertyName), " property name cannot be null or emptry");
39 ModelPropertyImpl dataModelProperty = (ModelPropertyImpl)this.Owner.Properties[this.PropertyName];
40 ModelItem oldValue = dataModelProperty.Value;
41 if ((oldValue == null && this.NewValue == null) ||
42 (oldValue != null && this.NewValue != null && oldValue.GetCurrentValue().Equals(this.NewValue.GetCurrentValue())))
46 dataModelProperty.SetValueCore(this.NewValue);
47 ModelChangeInfo changeInfo = ModelChangeInfoImpl.CreatePropertyChanged(this.Owner, this.PropertyName, this.OldValue, this.NewValue);
48 this.ModelTreeManager.NotifyPropertyChange(dataModelProperty, changeInfo);
52 public override Change GetInverse()
54 return new PropertyChange()
56 ModelTreeManager = this.ModelTreeManager,
58 OldValue = this.NewValue,
59 NewValue = this.OldValue,
60 PropertyName = this.PropertyName