|
|
|
@ -1,3 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Data; |
|
|
|
@ -5,12 +7,49 @@ using Avalonia.Diagnostics; |
|
|
|
using Avalonia.Markup.Xaml.Templates; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Xunit; |
|
|
|
|
|
|
|
namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
{ |
|
|
|
public class ControlTemplateTests : XamlTestBase |
|
|
|
{ |
|
|
|
[Fact] |
|
|
|
public void StyledProperties_Should_Be_Set_In_The_ControlTemplate() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
|
|
|
|
var xaml = @"
|
|
|
|
<Window xmlns='https://github.com/avaloniaui'
|
|
|
|
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
|
|
|
xmlns:controls=""using:Avalonia.Markup.Xaml.UnitTests.Xaml""> |
|
|
|
<Button> |
|
|
|
<Button.Template> |
|
|
|
<ControlTemplate> |
|
|
|
<controls:ListBoxHierachyLine> |
|
|
|
<controls:ListBoxHierachyLine.LineDashStyle> |
|
|
|
<DashStyle Dashes=""2,2"" Offset=""1"" /> |
|
|
|
</controls:ListBoxHierachyLine.LineDashStyle> |
|
|
|
</controls:ListBoxHierachyLine> |
|
|
|
</ControlTemplate> |
|
|
|
</Button.Template> |
|
|
|
</Button> |
|
|
|
</Window>";
|
|
|
|
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); |
|
|
|
var button = (Button)window.Content; |
|
|
|
|
|
|
|
window.ApplyTemplate(); |
|
|
|
button.ApplyTemplate(); |
|
|
|
var listBoxHierarchyLine = button.GetVisualChildren().ElementAt(0) as ListBoxHierachyLine; |
|
|
|
Assert.Equal(1, listBoxHierarchyLine.LineDashStyle.Offset); |
|
|
|
Assert.Equal(2, listBoxHierarchyLine.LineDashStyle.Dashes.Count); |
|
|
|
Assert.Equal(2, listBoxHierarchyLine.LineDashStyle.Dashes[0]); |
|
|
|
Assert.Equal(2, listBoxHierarchyLine.LineDashStyle.Dashes[1]); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Inline_ControlTemplate_Styled_Values_Are_Set_With_Style_Priority() |
|
|
|
{ |
|
|
|
@ -270,4 +309,15 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|
|
|
Assert.Equal("Bar", bar.Name); |
|
|
|
} |
|
|
|
} |
|
|
|
public class ListBoxHierachyLine : Panel |
|
|
|
{ |
|
|
|
public static readonly StyledProperty<DashStyle> LineDashStyleProperty = |
|
|
|
AvaloniaProperty.Register<ListBoxHierachyLine, DashStyle>(nameof(LineDashStyle)); |
|
|
|
|
|
|
|
public DashStyle LineDashStyle |
|
|
|
{ |
|
|
|
get => GetValue(LineDashStyleProperty); |
|
|
|
set => SetValue(LineDashStyleProperty, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|