Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: DataGrid copying data clears DataGridCells #7786

Merged
merged 4 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}