Exemple #1
0
        public void StyleResource_Can_Be_Assigned_To_Property()
        {
            var xaml = @"
<UserControl xmlns='https://github.com/avaloniaui'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <UserControl.Styles>
        <Style>
            <Style.Resources>
                <SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
            </Style.Resources>
        </Style>
    </UserControl.Styles>

    <Border Name='border' Background='{StyleResource brush}'/>
</UserControl>";

            var loader = new AvaloniaXamlLoader();
            var userControl = (UserControl)loader.Load(xaml);
            var border = userControl.FindControl<Border>("border");

            DelayedBinding.ApplyBindings(border);

            var brush = (SolidColorBrush)border.Background;
            Assert.Equal(0xff506070, brush.Color.ToUint32());
        }
Exemple #2
0
        public void Setter_Can_Contain_Template()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
            <Window xmlns='https://github.com/avaloniaui'
            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <Window.Styles>
            <Style Selector='ContentControl'>
            <Setter Property='Content'>
                <Template>
                    <TextBlock>Hello World!</TextBlock>
                </Template>
            </Setter>
            </Style>
            </Window.Styles>

            <ContentControl Name='target'/>
            </Window>";

                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var target = window.Find<ContentControl>("target");

                Assert.IsType<TextBlock>(target.Content);
                Assert.Equal("Hello World!", ((TextBlock)target.Content).Text);
            }
        }
        public void DataTemplate_Can_Contain_Name()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:sys='clr-namespace:System;assembly=mscorlib'>
    <Window.DataTemplates>
        <DataTemplate DataType='{Type sys:String}'>
            <Canvas Name='foo'/>
        </DataTemplate>
    </Window.DataTemplates>
    <ContentControl Name='target' Content='Foo'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var target = window.FindControl<ContentControl>("target");

                window.ApplyTemplate();
                target.ApplyTemplate();
                ((ContentPresenter)target.Presenter).UpdateChild();

                Assert.IsType<Canvas>(target.Presenter.Child);
            }
        }
Exemple #4
0
        public void Binding_Should_Be_Assigned_To_Setter_Value_Instead_Of_Bound()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformWrapper))
            {
                var xaml = "<Style xmlns='https://github.com/avaloniaui'><Setter Value='{Binding}'/></Style>";
                var loader = new AvaloniaXamlLoader();
                var style = (Style)loader.Load(xaml);
                var setter = (Setter)(style.Setters.First());

                Assert.IsType<Binding>(setter.Value);
            }                
        }
        public void Binding_Should_Be_Assigned_To_ItemsSource_Instead_Of_Bound()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformWrapper))
            {
                var xaml = "<DataTemplates xmlns='https://github.com/avaloniaui'><TreeDataTemplate ItemsSource='{Binding}'/></DataTemplates>";
                var loader = new AvaloniaXamlLoader();
                var templates = (DataTemplates)loader.Load(xaml);
                var template = (TreeDataTemplate)(templates.First());

                Assert.IsType<Binding>(template.ItemsSource);
            }                
        }
Exemple #6
0
        public void Named_Control_Is_Added_To_NameScope()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <Button Name='button'>Foo</Button>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl<Button>("button");

                Assert.Equal("Foo", button.Content);
            }
        }
        public void Binding_ProgressBar_Value_To_Invalid_Value_Uses_FallbackValue()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'>
    <ProgressBar Maximum='10' Value='{Binding Value, FallbackValue=3}'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var progressBar = (ProgressBar)window.Content;

                window.DataContext = new { Value = "foo" };
                window.ApplyTemplate();

                Assert.Equal(3, progressBar.Value);
            }
        }
        public void Can_Set_DataContext_In_DataTemplate()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests;assembly=Avalonia.Markup.Xaml.UnitTests'>
    <Window.DataTemplates>
        <DataTemplate DataType='{Type local:TestViewModel}'>
            <Canvas Name='foo' DataContext='{Binding Child}'/>
        </DataTemplate>
    </Window.DataTemplates>
    <ContentControl Name='target' Content='{Binding Child}'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var target = window.FindControl<ContentControl>("target");

                var viewModel = new TestViewModel
                {
                    String = "Root",
                    Child = new TestViewModel
                    {
                        String = "Child",
                        Child = new TestViewModel
                        {
                            String = "Grandchild",
                        }
                    },
                };

                window.DataContext = viewModel;

                window.ApplyTemplate();
                target.ApplyTemplate();
                ((ContentPresenter)target.Presenter).UpdateChild();

                var canvas = (Canvas)target.Presenter.Child;
                Assert.Same(viewModel, target.DataContext);
                Assert.Same(viewModel.Child, target.Presenter.DataContext);
                Assert.Same(viewModel.Child.Child, canvas.DataContext);
            }
        }
Exemple #9
0
        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}'/>
</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);
            }
        }
Exemple #10
0
        public void Can_Bind_Control_To_Non_Control()
        {
            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='Foo'>
        <Button.Tag>
            <local:NonControl Control='{Binding #button}'/>
        </Button.Tag>
    </Button>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl<Button>("button");

                Assert.Same(button, ((NonControl)button.Tag).Control);
            }
        }
Exemple #11
0
        public void Color_Can_Be_Added_To_Style_Resources()
        {
            using (UnitTestApplication.Start(TestServices.MockPlatformWrapper))
            {
                var xaml = @"
            <UserControl xmlns='https://github.com/avaloniaui'
             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <UserControl.Styles>
            <Style>
            <Style.Resources>
                <Color x:Key='color'>#ff506070</Color>
            </Style.Resources>
            </Style>
            </UserControl.Styles>
            </UserControl>";
                var loader = new AvaloniaXamlLoader();
                var userControl = (UserControl)loader.Load(xaml);
                var color = (Color)((Style)userControl.Styles[0]).Resources["color"];

                Assert.Equal(0xff506070, color.ToUint32());
            }
        }
Exemple #12
0
        public void Control_Is_Added_To_Parent_Before_Properties_Are_Set()
        {
            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'>
    <local:InitializationOrderTracker Width='100'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var tracker = (InitializationOrderTracker)window.Content;

                var attached = tracker.Order.IndexOf("AttachedToLogicalTree");
                var widthChanged = tracker.Order.IndexOf("Property Width Changed");

                Assert.NotEqual(-1, attached);
                Assert.NotEqual(-1, widthChanged);
                Assert.True(attached < widthChanged);
            }
        }
        public void Invalid_FallbackValue_Logs_Error()
        {
            var called = false;

            LogCallback checkLogMessage = (level, area, src, mt, pv) =>
            {
                if (level == LogEventLevel.Error &&
                    area == LogArea.Binding &&
                    mt == "Error in binding to {Target}.{Property}: {Message}" &&
                    pv.Length == 3 &&
                    pv[0] is ProgressBar &&
                    object.ReferenceEquals(pv[1], ProgressBar.ValueProperty) &&
                    (string)pv[2] == "Could not convert FallbackValue 'bar' to 'System.Double'")
                {
                    called = true;
                }
            };

            using (UnitTestApplication.Start(TestServices.StyledWindow))
            using (TestLogSink.Start(checkLogMessage))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'>
    <ProgressBar Maximum='10' Value='{Binding Value, FallbackValue=bar}'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var progressBar = (ProgressBar)window.Content;

                window.DataContext = new { Value = "foo" };
                window.ApplyTemplate();

                Assert.Equal(0, progressBar.Value);
                Assert.True(called);
            }
        }
Exemple #14
0
        public void StyleResource_Can_Be_Assigned_To_StyleResource_Property()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
            <Window xmlns='https://github.com/avaloniaui'
            xmlns:mut='https://github.com/avaloniaui/mutable'
            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <Window.Styles>
            <Style>
            <Style.Resources>
                <Color x:Key='color'>#ff506070</Color>
                <mut:SolidColorBrush x:Key='brush' Color='{StyleResource color}'/>
            </Style.Resources>
            </Style>
            </Window.Styles>
            <Button Name='button' Background='{StyleResource brush}'/>
            </Window>";

                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var brush = (Avalonia.Media.Mutable.SolidColorBrush)window.FindStyleResource("brush");
                var button = window.FindControl<Button>("button");

                DelayedBinding.ApplyBindings(button);

                var buttonBrush = (Avalonia.Media.Mutable.SolidColorBrush)button.Background;

                Assert.Equal(0xff506070, brush.Color.ToUint32());
                Assert.Equal(0xff506070, buttonBrush.Color.ToUint32());
            }
        }
Exemple #15
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     resourceListView = this.FindControl <DataGrid>("resourceListView");
     CommandBindings.Add(new RoutedCommandBinding(global::AvaloniaEdit.ApplicationCommands.Copy, ExecuteCopy, CanExecuteCopy));
 }
Exemple #16
0
 public AggregatorControl()
 {
     AvaloniaXamlLoader.Load(this);
 }
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     this.FindControl <MyExpandable>("_expander").ExpandedChanged += _ExpandedChanged;
 }
Exemple #18
0
 public override void Initialize()
 {
     AvaloniaXamlLoader.Load(this);
 }
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            Root = this.Get <Grid>("Root");
        }
Exemple #20
0
        void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            Target = this.Get <Dial>("Target");
        }
Exemple #21
0
 public ProfileImage()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #22
0
 public AboutAvaloniaDialog()
 {
     AvaloniaXamlLoader.Load(this);
     DataContext = this;
 }
Exemple #23
0
 void InitializeComponent() => AvaloniaXamlLoader.Load(this);
Exemple #24
0
 public MainView()
 {
     this.WhenActivated(disposables => { });
     AvaloniaXamlLoader.Load(this);
 }
Exemple #25
0
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);

            _backgroundJobs = _backgroundWorker.Init();
        }
Exemple #26
0
 public NoneStructProjectionControl()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #27
0
 public WorkspaceTabControl()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #28
0
        private static void UpdateXaml2(Dictionary <string, object> dic)
        {
            var     xamlInfo = new DesignerApiXamlFileInfo(dic);
            Window  window;
            Control control;

            using (PlatformManager.DesignerMode())
            {
                var loader = new AvaloniaXamlLoader();
                var stream = new MemoryStream(Encoding.UTF8.GetBytes(xamlInfo.Xaml));



                Uri baseUri = null;
                if (xamlInfo.AssemblyPath != null)
                {
                    //Fabricate fake Uri
                    baseUri =
                        new Uri("resm:Fake.xaml?assembly=" + Path.GetFileNameWithoutExtension(xamlInfo.AssemblyPath));
                }

                var loaded = loader.Load(stream, null, baseUri);
                var styles = loaded as Styles;
                if (styles != null)
                {
                    var substitute = Design.GetPreviewWith(styles) ??
                                     styles.Select(Design.GetPreviewWith).FirstOrDefault(s => s != null);
                    if (substitute != null)
                    {
                        substitute.Styles.AddRange(styles);
                        control = substitute;
                    }
                    else
                    {
                        control = new StackPanel
                        {
                            Children =
                            {
                                new TextBlock {
                                    Text = "Styles can't be previewed without Design.PreviewWith. Add"
                                },
                                new TextBlock {
                                    Text = "<Design.PreviewWith>"
                                },
                                new TextBlock {
                                    Text = "    <Border Padding=20><!-- YOUR CONTROL FOR PREVIEW HERE--></Border>"
                                },
                                new TextBlock {
                                    Text = "<Design.PreviewWith>"
                                },
                                new TextBlock {
                                    Text = "before setters in your first Style"
                                }
                            }
                        }
                    };
                }
                if (loaded is Application)
                {
                    control = new TextBlock {
                        Text = "Application can't be previewed in design view"
                    }
                }
                ;
                else
                {
                    control = (Control)loaded;
                }

                window = control as Window;
                if (window == null)
                {
                    window = new Window()
                    {
                        Content = (Control)control
                    };
                }

                if (!window.IsSet(Window.SizeToContentProperty))
                {
                    window.SizeToContent = SizeToContent.WidthAndHeight;
                }
            }

            s_currentWindow?.Close();
            s_currentWindow = window;
            window.Show();
            Design.ApplyDesignerProperties(window, control);
            Api.OnWindowCreated?.Invoke(window.PlatformImpl.Handle.Handle);
            Api.OnResize?.Invoke();
        }
    }
 private void InitializeComponent()
 {
     this.WhenActivated(disposables => { });
     AvaloniaXamlLoader.Load(this);
 }
 public AutoCompleteBoxStyles()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #31
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #32
0
        public override void Initialize()
        {
            Styles.Insert(0, FluentLight);

            AvaloniaXamlLoader.Load(this);
        }
 public PublishItemView()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #34
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     this.Closing += (s, e) => ViewModel.DisposeResidents();
 }
Exemple #35
0
        public void Setter_Value_Is_Bound_Directly_If_The_Target_Type_Derives_From_ITemplate()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <Window.Styles>
        <Style Selector=':is(Control)'>
		  <Setter Property='FocusAdorner'>
			<FocusAdornerTemplate>
			  <Rectangle Stroke='Black'
						 StrokeThickness='1'
						 StrokeDashArray='1,2'/>
			</FocusAdornerTemplate>
		  </Setter>
		</Style>
	</Window.Styles>

    <TextBlock Name='target'/>    
</Window>";

                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var target = window.Find<TextBlock>("target");

                Assert.NotNull(target.FocusAdorner);
            }
        }
Exemple #36
0
        void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            ClearMode = this.Get <ComboBox>("ClearMode");
        }
Exemple #37
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     iconImage = this.Get <Image>("Icon");
 }
 public KeyResultNodeControl()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #39
0
        public void StyleResource_Can_Be_Assigned_To_Setter()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
            <Window xmlns='https://github.com/avaloniaui'
            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <Window.Styles>
            <Style>
            <Style.Resources>
                <SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush>
            </Style.Resources>
            </Style>
            <Style Selector='Button'>
            <Setter Property='Background' Value='{StyleResource brush}'/>
            </Style>
            </Window.Styles>
            <Button Name='button'/>
            </Window>";

                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl<Button>("button");
                var brush = (SolidColorBrush)button.Background;

                Assert.Equal(0xff506070, brush.Color.ToUint32());
            }
        }
 public MarkdownStyleGithubLike()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #41
0
        public void StyleResource_Can_Be_Found_Across_Xaml_Files()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
            <Window xmlns='https://github.com/avaloniaui'
            xmlns:mut='https://github.com/avaloniaui/mutable'
            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <Window.Styles>
            <StyleInclude Source='resm:Avalonia.Markup.Xaml.UnitTests.Xaml.Style1.xaml?assembly=Avalonia.Markup.Xaml.UnitTests'/>
            <StyleInclude Source='resm:Avalonia.Markup.Xaml.UnitTests.Xaml.Style2.xaml?assembly=Avalonia.Markup.Xaml.UnitTests'/>
            </Window.Styles>
            <Border Name='border' Background='{StyleResource RedBrush}'/>
            </Window>";

                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var border = window.FindControl<Border>("border");
                var borderBrush = (Avalonia.Media.Mutable.SolidColorBrush)border.Background;

                Assert.NotNull(borderBrush);
                Assert.Equal(0xffff0000, borderBrush.Color.ToUint32());
            }
        }
Exemple #42
0
 public MainWindow()
 {
     AvaloniaXamlLoader.Load(this);
     this.DataContext = new MainWindowViewModel();
 }
Exemple #43
0
        public void StyleResource_Can_Be_Found_In_TopLevel_Styles()
        {
            var xaml = @"
            <Styles xmlns='https://github.com/avaloniaui'
            xmlns:mut='https://github.com/avaloniaui/mutable'
            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
            <Style>
            <Style.Resources>
            <Color x:Key='color'>#ff506070</Color>
            <mut:SolidColorBrush x:Key='brush' Color='{StyleResource color}'/>
            </Style.Resources>
            </Style>
            </Styles>";

            var loader = new AvaloniaXamlLoader();
            var styles = (Styles)loader.Load(xaml);
            var brush = (Avalonia.Media.Mutable.SolidColorBrush)styles.FindResource("brush");

            Assert.Equal(0xff506070, brush.Color.ToUint32());
        }
 public WelcomeControl()
 {
     AvaloniaXamlLoader.Load(this);
 }
Exemple #45
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            SupportersTextBlock = this.FindControl <TextBlock>("SupportersTextBlock");
        }
 public LoginPage()
 {
     this.WhenActivated(disposables => { });
     AvaloniaXamlLoader.Load(this);
 }
Exemple #47
0
        public void Binding_DataContext_To_Inherited_DataContext_Works()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var xaml = @"
<Window xmlns='https://github.com/avaloniaui'
        xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
    <Border DataContext='{Binding Foo}'/>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var border = (Border)window.Content;

                window.DataContext = new { Foo = "foo" };
                window.ApplyTemplate();

                Assert.Equal("foo", border.DataContext);
            }
        }
Exemple #48
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     DataContextChanged += EnumEditor_DataContextChanged;
 }
Exemple #49
0
        public void Can_Bind_To_DataContext_Of_Anchor_On_Non_Control()
        {
            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'>
        <Button.Tag>
            <local:NonControl String='{Binding Foo}'/>
        </Button.Tag>
    </Button>
</Window>";
                var loader = new AvaloniaXamlLoader();
                var window = (Window)loader.Load(xaml);
                var button = window.FindControl<Button>("button");

                button.DataContext = new { Foo = "foo" };

                Assert.Equal("foo", ((NonControl)button.Tag).String);
            }
        }
 public TextMessageControl()
 {
     AvaloniaXamlLoader.Load(this);
 }