Adding New Style
With dotnet cli
sh
dotnet new avalonia.styles -o Styles -n NewStyle
1
Default Template
Style template ships with a portion for previewer where you can add testing controls to see whether those styles works properly.
xml
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<!-- Add Controls for Previewer Here -->
</Border>
</Design.PreviewWith>
<!-- Add Styles Here -->
</Styles>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
Define a Style
A style starts with a Selector
which is the rule of target matching, for figuring out which control should have those contained styling. Contained styling is some key-value pair on properties.
xml
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<!-- Add Controls for Previewer Here -->
</Border>
</Design.PreviewWith>
<!-- Add Styles Here -->
<Style Selector="TextBlock.h1">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="15" />
<Setter Property="Margin" Value="5" />
</Style>
</Styles>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16