Ejemplo n.º 1
0
        public void Binding_To_Attached_Property_In_Style_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'>
    <Window.Styles>
        <Style Selector='TextBlock'>
            <Setter Property='local:TestControl.Double' Value='{Binding}'/>
        </Style>
    </Window.Styles>
    <TextBlock/>
</Window>";
                var loader    = new AvaloniaXamlLoader();
                var window    = (Window)loader.Load(xaml);
                var textBlock = (TextBlock)window.Content;

                window.DataContext = 5.6;
                window.ApplyTemplate();

                Assert.Equal(5.6, AttachedPropertyOwner.GetDouble(textBlock));
            }
        }
Ejemplo n.º 2
0
        public void Binding_To_Attached_Property_Using_AddOwnered_Type_Works()
        {
            using (UnitTestApplication.Start(TestServices.MockWindowingPlatform))
            {
                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'>
    <TextBlock local:TestControl.Double='{Binding}'/>
</Window>";
                var window    = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
                var textBlock = (TextBlock)window.Content;

                window.DataContext = 5.6;
                window.ApplyTemplate();

                Assert.Equal(5.6, AttachedPropertyOwner.GetDouble(textBlock));
            }
        }