Skip to content

Commit 319305f

Browse files
committed
[Linux] Add Label styling
1 parent ed576e1 commit 319305f

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

samples/SampleApp/DemoPages/LabelDemo.axaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
5+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="650"
66
x:Class="SampleApp.DemoPages.LabelDemo">
77

8-
<StackPanel Margin="10" Width="350" Spacing="15" HorizontalAlignment="Left">
8+
<StackPanel Margin="10" Width="400" Spacing="15" HorizontalAlignment="Left">
99
<StackPanel>
1010
<Label Content="Label" Target="{Binding #Input1}" />
1111
<TextBox Name="Input1" Text="Input" />
1212
</StackPanel>
1313

1414
<StackPanel>
15-
<Label Content="Label disabled" IsEnabled="False" Target="{Binding #Input2}" />
15+
<Label Content="Label explicitly disabled" IsEnabled="False" Target="{Binding #Input2}" />
1616
<TextBox Name="Input2" Text="Linked input control not affected" />
1717
</StackPanel>
1818

@@ -31,15 +31,20 @@
3131
<TextBox Name="Input5" Text="No mnemonics, no accesibility, no label-click-to-focus" />
3232
</StackPanel>
3333

34+
35+
<TextBlock Margin="0 20 0 0">
36+
To automatically show a colon after labels add a style:<LineBreak />
37+
<TextBlock Classes="code" Text="&lt;Style Selector=&quot;Label /template/ TextBlock#Colon&quot;&gt;" /><LineBreak />
38+
<TextBlock Classes="code" Text="&lt;Setter Property=&quot;IsVisible&quot; Value=&quot;True&quot; /&gt;" />
39+
</TextBlock>
40+
3441
<StackPanel>
35-
<Label Content="Label.form" Classes="form" Target="{Binding #Input6}" />
42+
<Label Content="Label" Classes="form" Target="{Binding #Input6}" />
3643
<TextBox Name="Input6" Text="Colon automatically added" />
3744
</StackPanel>
3845

3946

40-
<TextBlock Classes="section-title" Text="Grid.form or Grid.compact-form" Margin="0 20 0 0" />
41-
<TextBlock Text="Colons added to all labels" />
42-
<Grid Classes="form" ColumnDefinitions="Auto, *" RowDefinitions="Auto,Auto" Margin="10 0">
47+
<Grid Classes="form" ColumnDefinitions="Auto, *" RowDefinitions="Auto,Auto" Margin="10 0" ColumnSpacing="4" RowSpacing="4">
4348
<Label Content="_First" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Target="{Binding #FirstNameBox}" />
4449
<TextBox Name="FirstNameBox" Grid.Row="0" Grid.Column="1" Text="Otto" />
4550

samples/SampleApp/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
</TabItem>
121121
<TabItem IsSelected="True">
122122
<TabItem.Header>
123-
<controls:SampleItemHeader Title="Label" ApplicableTo="MacOS" />
123+
<controls:SampleItemHeader Title="Label" ApplicableTo="MacOS, Windows - DevExpress, Linux - Yaru" />
124124
</TabItem.Header>
125125
<demoPages:LabelDemo />
126126
</TabItem>

samples/SampleApp/Styles.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<Setter Property="VerticalAlignment" Value="Center" />
4545
</Style>
4646

47-
<!-- This rule is also used in RDM Styles.MacOS-->
47+
<!-- Example for consumer's styles accessing the colon (this rule is also used in RDM Styles.MacOS) -->
4848
<Style
4949
Selector="Grid.form > Label /template/ TextBlock#Colon,
5050
Label.form /template/ TextBlock#Colon,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- Based off https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Themes.Fluent/Controls/Label.xaml -->
2+
3+
<ResourceDictionary xmlns="https://github.com/avaloniaui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
x:ClassModifier="internal">
6+
7+
<ControlTheme x:Key="{x:Type Label}" TargetType="Label">
8+
<Setter Property="Padding" Value="3" />
9+
<Setter Property="IsEnabled" Value="{Binding $self.Target.IsEnabled, FallbackValue=True}" />
10+
<Setter Property="Template">
11+
<ControlTemplate>
12+
<StackPanel Orientation="Horizontal" Margin="{TemplateBinding Padding}">
13+
<ContentPresenter Name="PART_ContentPresenter"
14+
Background="{TemplateBinding Background}"
15+
BorderBrush="{TemplateBinding BorderBrush}"
16+
BorderThickness="{TemplateBinding BorderThickness}"
17+
CornerRadius="{TemplateBinding CornerRadius}"
18+
ContentTemplate="{TemplateBinding ContentTemplate}"
19+
Content="{TemplateBinding Content}"
20+
RecognizesAccessKey="True"
21+
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
22+
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
23+
<!-- TextBlock#Colon can be used in styles to automatically display colon after each label (cp. SampleApp/styles.axaml) -->
24+
<TextBlock
25+
Name="Colon"
26+
Text=":"
27+
IsVisible="False" />
28+
</StackPanel>
29+
</ControlTemplate>
30+
</Setter>
31+
32+
<Style Selector="^:disabled">
33+
<Setter Property="Foreground" Value="{DynamicResource ForegroundLowBrush}" />
34+
</Style>
35+
36+
</ControlTheme>
37+
</ResourceDictionary>

src/Devolutions.AvaloniaTheme.Linux/Controls/_index.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<MergeResourceInclude Source="DataGrid.axaml" />
1515
<MergeResourceInclude Source="EmbeddableControlRoot.axaml" />
1616
<MergeResourceInclude Source="Expander.axaml" />
17+
<MergeResourceInclude Source="Label.axaml" />
1718
<MergeResourceInclude Source="ListBox.axaml" />
1819
<MergeResourceInclude Source="NumericUpDown.axaml" />
1920
<MergeResourceInclude Source="TabItem.axaml" />

0 commit comments

Comments
 (0)