Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Reset does not work .NET Properties so store the old Value
Browse files Browse the repository at this point in the history
  • Loading branch information
jogibear9988 committed Jun 22, 2015
1 parent 8992783 commit c7a24a9
Showing 1 changed file with 16 additions and 2 deletions.
Expand Up @@ -197,6 +197,11 @@ public override string TextValue
}

public override void SetValue(object value)
{
SetValue(value, false);
}

private void SetValue(object value, bool withoutUndo)
{
XamlPropertyValue newValue;
if (value == null) {
Expand All @@ -218,7 +223,7 @@ public override void SetValue(object value)
}

UndoService undoService = _designItem.Services.GetService<UndoService>();
if (undoService != null)
if (undoService != null && !withoutUndo)
undoService.Execute(new PropertyChangeAction(this, newValue, true));
else
SetValueInternal(newValue);
Expand Down Expand Up @@ -251,6 +256,7 @@ public sealed class PropertyChangeAction : ITransactionItem
{
readonly XamlModelProperty property;
readonly XamlPropertyValue oldValue;
readonly object oldValueOnInstance;
XamlPropertyValue newValue;
readonly bool oldIsSet;
bool newIsSet;
Expand All @@ -264,6 +270,7 @@ public PropertyChangeAction(XamlModelProperty property, XamlPropertyValue newVal

oldIsSet = property._property.IsSet;
oldValue = property._property.PropertyValue;
oldValueOnInstance = property._property.ValueOnInstance;

if (oldIsSet && oldValue == null && property.IsCollection) {
collectionTransactionItem = property._collectionElements.CreateResetTransaction();
Expand Down Expand Up @@ -300,8 +307,15 @@ public void Undo()
property.SetValueInternal(oldValue);
}
}
else
else {
try {
property.SetValue(oldValueOnInstance, true);
}
catch(Exception)
{ }

property.ResetInternal();
}
}

public System.Collections.Generic.ICollection<DesignItem> AffectedElements {
Expand Down

0 comments on commit c7a24a9

Please sign in to comment.