Browse Source
Merge branch 'master' into fixes/2451-build-fails
pull/2488/head
Steven Kirk
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
56 additions and
3 deletions
-
src/Avalonia.Base/Data/BindingOperations.cs
-
src/Avalonia.Base/Data/Core/PropertyAccessorNode.cs
-
tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs
-
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BindingTests.cs
|
|
|
@ -65,7 +65,11 @@ namespace Avalonia.Data |
|
|
|
return Disposable.Empty; |
|
|
|
} |
|
|
|
case BindingMode.OneWayToSource: |
|
|
|
return target.GetObservable(property).Subscribe(binding.Subject); |
|
|
|
return Observable.CombineLatest( |
|
|
|
binding.Observable, |
|
|
|
target.GetObservable(property), |
|
|
|
(_, v) => v) |
|
|
|
.Subscribe(x => binding.Subject.OnNext(x)); |
|
|
|
default: |
|
|
|
throw new ArgumentException("Invalid binding mode."); |
|
|
|
} |
|
|
|
|
|
|
|
@ -59,8 +59,8 @@ namespace Avalonia.Data.Core |
|
|
|
$"Could not find a matching property accessor for {PropertyName}."); |
|
|
|
} |
|
|
|
|
|
|
|
accessor.Subscribe(ValueChanged); |
|
|
|
_accessor = accessor; |
|
|
|
accessor.Subscribe(ValueChanged); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void StopListeningCore() |
|
|
|
|
|
|
|
@ -100,6 +100,28 @@ namespace Avalonia.Markup.UnitTests.Data |
|
|
|
Assert.Equal("baz", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void OneWayToSource_Binding_Should_React_To_DataContext_Changed() |
|
|
|
{ |
|
|
|
var target = new TextBlock { Text = "bar" }; |
|
|
|
var binding = new Binding |
|
|
|
{ |
|
|
|
Path = "Foo", |
|
|
|
Mode = BindingMode.OneWayToSource, |
|
|
|
}; |
|
|
|
|
|
|
|
target.Bind(TextBox.TextProperty, binding); |
|
|
|
|
|
|
|
var source = new Source { Foo = "foo" }; |
|
|
|
target.DataContext = source; |
|
|
|
|
|
|
|
Assert.Equal("bar", source.Foo); |
|
|
|
target.Text = "baz"; |
|
|
|
Assert.Equal("baz", source.Foo); |
|
|
|
source.Foo = "quz"; |
|
|
|
Assert.Equal("baz", target.Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Default_BindingMode_Should_Be_Used() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -329,6 +329,33 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
|
|
|
|
Assert.Equal("Hello world", textBlock.Text); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Binding_OneWayToSource_Works() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
ShowInTaskbar='{Binding ShowInTaskbar, Mode=OneWayToSource}'> |
|
|
|
</Window>";
|
|
|
|
var loader = new AvaloniaXamlLoader(); |
|
|
|
var window = (Window)loader.Load(xaml); |
|
|
|
var viewModel = new WindowViewModel(); |
|
|
|
|
|
|
|
window.DataContext = viewModel; |
|
|
|
window.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.True(window.ShowInTaskbar); |
|
|
|
Assert.True(viewModel.ShowInTaskbar); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class WindowViewModel |
|
|
|
{ |
|
|
|
public bool ShowInTaskbar { get; set; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|