2 changed files with 58 additions and 0 deletions
@ -0,0 +1,57 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.Reactive.Subjects; |
|||
using Avalonia.Controls; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|||
{ |
|||
public class BindingTests_RelativeSource |
|||
{ |
|||
[Fact] |
|||
public void Binding_To_DataContext_Works() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<Window xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|||
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|||
<Button Name='button' Content='{Binding Foo, RelativeSource={RelativeSource DataContext}}'/> |
|||
</Window>";
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var window = (Window)loader.Load(xaml); |
|||
var button = window.FindControl<Button>("button"); |
|||
|
|||
button.DataContext = new { Foo = "foo" }; |
|||
window.ApplyTemplate(); |
|||
|
|||
Assert.Equal("foo", button.Content); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Binding_To_Self_Works() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<Window xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|||
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> |
|||
<Button Name='button' Content='{Binding Name, RelativeSource={RelativeSource Self}}'/> |
|||
</Window>";
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var window = (Window)loader.Load(xaml); |
|||
var button = window.FindControl<Button>("button"); |
|||
|
|||
button.DataContext = new { Foo = "foo" }; |
|||
window.ApplyTemplate(); |
|||
|
|||
Assert.Equal("button", button.Content); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue