User Control
A minimal control customization starter without the capability to be restyled.
Minimal example
xml
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication1.MyUserControl">
Welcome to Avalonia!
</UserControl>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
As a templated control
As we mentioned earlier, a UserControl
is a TemplatedControl with a default template. So we can set styles to make it a template.
xml
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:control="using:AvaloniaApplication"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication.MyUserControl">
<UserControl.Styles>
<Style Selector="control|MyUserControl">
<Setter Property="Template">
<ControlTemplate>
<TextBlock Text="Hello from template" TextAlignment="Center" Width="200" Height="20" Background="Gray"/>
</ControlTemplate>
</Setter>
</Style>
</UserControl.Styles>
</UserControl>
``
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19