Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#7786 from timunie/fix/DataGridCopyClear…
Browse files Browse the repository at this point in the history
…sContent

Fix: DataGrid copying data clears DataGridCells
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jun 1, 2022
1 parent 10a0f6a commit d2f3210
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Avalonia.Base/Data/BindingOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ public static IDisposable Apply(

private sealed class TwoWayBindingDisposable : IDisposable
{
private readonly IDisposable _first;
private readonly IDisposable _second;
private readonly IDisposable _toTargetSubscription;
private readonly IDisposable _fromTargetSubsription;

private bool _isDisposed;

public TwoWayBindingDisposable(IDisposable first, IDisposable second)
public TwoWayBindingDisposable(IDisposable toTargetSubscription, IDisposable fromTargetSubsription)
{
_first = first;
_second = second;
_toTargetSubscription = toTargetSubscription;
_fromTargetSubsription = fromTargetSubsription;
}

public void Dispose()
Expand All @@ -116,8 +117,8 @@ public void Dispose()
return;
}

_first.Dispose();
_second.Dispose();
_fromTargetSubsription.Dispose();
_toTargetSubscription.Dispose();

_isDisposed = true;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,30 @@ public void Disposing_Completed_Binding_Does_Not_Throw()
subscription.Dispose();
}

[Fact]
public void TwoWay_Binding_Should_Not_Call_Setter_On_Creation_With_Value()
{
var target = new Class1();
var source = new TestTwoWayBindingViewModel() { Value = 1 };
source.ResetSetterCalled();

target.Bind(Class1.DoubleValueProperty, new Binding(nameof(source.Value), BindingMode.TwoWay) { Source = source });

Assert.False(source.SetterCalled);
}

[Fact]
public void TwoWay_Binding_Should_Not_Call_Setter_On_Creation_Indexer_With_Value()
{
var target = new Class1();
var source = new TestTwoWayBindingViewModel() { [0] = 1 };
source.ResetSetterCalled();

target.Bind(Class1.DoubleValueProperty, new Binding("[0]", BindingMode.TwoWay) { Source = source });

Assert.False(source.SetterCalled);
}

/// <summary>
/// Returns an observable that returns a single value but does not complete.
/// </summary>
Expand Down Expand Up @@ -943,6 +967,11 @@ public double this[int index]
}

public bool SetterCalled { get; private set; }

public void ResetSetterCalled()
{
SetterCalled = false;
}
}
}
}

0 comments on commit d2f3210

Please sign in to comment.