Skip to content

Commit 29d6692

Browse files
committed
Support Old Value on Property Change
1 parent d256bb4 commit 29d6692

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ internal XamlDesignItem RegisterXamlComponentRecursive(XamlObject obj)
201201
/// <summary>
202202
/// raises the Property changed Events
203203
/// </summary>
204-
internal void RaisePropertyChanged(XamlModelProperty property)
204+
internal void RaisePropertyChanged(XamlModelProperty property, object oldValue, object newValue)
205205
{
206206
var ev = this.PropertyChanged;
207207
if (ev != null) {
208-
ev(this, new DesignItemPropertyChangedEventArgs(property.DesignItem, property));
208+
ev(this, new DesignItemPropertyChangedEventArgs(property.DesignItem, property, oldValue, newValue));
209209
}
210210
}
211211

WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ public override IEnumerable<DesignItemProperty> AllSetProperties {
264264
get { return _xamlObject.Properties.Select(x => new XamlModelProperty(this, x)); }
265265
}
266266

267-
internal void NotifyPropertyChanged(XamlModelProperty property)
267+
internal void NotifyPropertyChanged(XamlModelProperty property, object oldValue, object newValue)
268268
{
269269
Debug.Assert(property != null);
270270
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs(property.Name));
271271

272-
((XamlComponentService)this.Services.Component).RaisePropertyChanged(property);
272+
((XamlComponentService)this.Services.Component).RaisePropertyChanged(property, oldValue, newValue);
273273
}
274274

275275
public override string ContentPropertyName {

WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ public string Title {
260260
public void Do()
261261
{
262262
collection.InsertInternal(index, item);
263-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
263+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, null, item);
264264
}
265265

266266
public void Undo()
267267
{
268268
collection.RemoveInternal(index, item);
269-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
269+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, item, null);
270270
}
271271

272272
public bool MergeWith(ITransactionItem other)
@@ -303,13 +303,13 @@ public string Title {
303303
public void Do()
304304
{
305305
collection.RemoveInternal(index, item);
306-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
306+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, item ,null);
307307
}
308308

309309
public void Undo()
310310
{
311311
collection.InsertInternal(index, item);
312-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
312+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, null, item);
313313
}
314314

315315
public bool MergeWith(ITransactionItem other)
@@ -340,14 +340,14 @@ public void Do()
340340
for (int i = items.Length - 1; i >= 0; i--) {
341341
collection.RemoveInternal(i, items[i]);
342342
}
343-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
343+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, items, null);
344344
}
345345
public void Undo()
346346
{
347347
for (int i = 0; i < items.Length; i++) {
348348
collection.InsertInternal(i, items[i]);
349349
}
350-
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty);
350+
collection.modelProperty.XamlDesignItem.NotifyPropertyChanged(collection.modelProperty, null, items);
351351
}
352352
public bool MergeWith(ITransactionItem other)
353353
{

WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ public override void SetValue(object value)
247247

248248
void SetValueInternal(XamlPropertyValue newValue)
249249
{
250+
var oldValue = _property.PropertyValue;
250251
_property.PropertyValue = newValue;
251-
_designItem.NotifyPropertyChanged(this);
252+
_designItem.NotifyPropertyChanged(this, oldValue, newValue);
252253
}
253254

254255
public override void Reset()
@@ -262,9 +263,11 @@ public override void Reset()
262263

263264
void ResetInternal()
264265
{
265-
if (_property.IsSet) {
266+
if (_property.IsSet)
267+
{
268+
var oldValue = _property.PropertyValue;
266269
_property.Reset();
267-
_designItem.NotifyPropertyChanged(this);
270+
_designItem.NotifyPropertyChanged(this, oldValue, null);
268271
}
269272
}
270273

WpfDesign/Project/EventArgs.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,48 @@ public DesignItem Item {
5050
public class DesignItemPropertyChangedEventArgs : DesignItemEventArgs
5151
{
5252
readonly DesignItemProperty _itemProperty;
53-
53+
readonly object _oldValue;
54+
readonly object _newValue;
55+
5456
/// <summary>
5557
/// Creates a new ComponentEventArgs instance.
5658
/// </summary>
5759
public DesignItemPropertyChangedEventArgs(DesignItem item, DesignItemProperty itemProperty) : base(item)
5860
{
5961
_itemProperty = itemProperty;
6062
}
61-
63+
64+
/// <summary>
65+
/// Creates a new ComponentEventArgs instance.
66+
/// </summary>
67+
public DesignItemPropertyChangedEventArgs(DesignItem item, DesignItemProperty itemProperty, object oldValue, object newValue) : this(item, itemProperty)
68+
{
69+
_oldValue = oldValue;
70+
_newValue = newValue;
71+
}
72+
6273
/// <summary>
6374
/// The property affected by the event.
6475
/// </summary>
6576
public DesignItemProperty ItemProperty {
6677
get { return _itemProperty; }
6778
}
79+
80+
/// <summary>
81+
/// Previous Value
82+
/// </summary>
83+
public object OldValue
84+
{
85+
get { return _oldValue; }
86+
}
87+
88+
/// <summary>
89+
/// New Value
90+
/// </summary>
91+
public object NewValue
92+
{
93+
get { return _newValue; }
94+
}
6895
}
6996

7097
/// <summary>

0 commit comments

Comments
 (0)