Browse Source

Improve styling

timunie 6 months ago
parent
commit
b1de1eccb9
  1. 1
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  2. 18
      src/Avalonia.Controls/Calendar/CalendarWeekNumberLabel.cs
  3. 4
      src/Avalonia.Themes.Fluent/Accents/FluentControlResources.xaml
  4. 28
      src/Avalonia.Themes.Fluent/Controls/CalendarWeekNumberLabel.xaml
  5. 30
      src/Avalonia.Themes.Simple/Controls/CalendarWeekNumberLabel.xaml

1
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -215,6 +215,7 @@ namespace Avalonia.Controls.Primitives
// Week-number cells — added after existing cells to preserve child indices 0–48. // Week-number cells — added after existing cells to preserve child indices 0–48.
// Header placeholder (row 0, col 0) // Header placeholder (row 0, col 0)
_weekNumberHeaderLabel = new CalendarWeekNumberLabel(); _weekNumberHeaderLabel = new CalendarWeekNumberLabel();
_weekNumberHeaderLabel.IsHeader = true;
_weekNumberHeaderLabel.SetValue(Grid.RowProperty, 0); _weekNumberHeaderLabel.SetValue(Grid.RowProperty, 0);
_weekNumberHeaderLabel.SetValue(Grid.ColumnProperty, 0); _weekNumberHeaderLabel.SetValue(Grid.ColumnProperty, 0);
children.Add(_weekNumberHeaderLabel); children.Add(_weekNumberHeaderLabel);

18
src/Avalonia.Controls/Calendar/CalendarWeekNumberLabel.cs

@ -4,8 +4,26 @@ namespace Avalonia.Controls.Primitives
/// Displays a week number in the month view of a <see cref="Calendar"/>. /// Displays a week number in the month view of a <see cref="Calendar"/>.
/// Apply styles targeting <see cref="CalendarWeekNumberLabel"/> to customise /// Apply styles targeting <see cref="CalendarWeekNumberLabel"/> to customise
/// the appearance — for example <c>FontWeight="Bold"</c>. /// the appearance — for example <c>FontWeight="Bold"</c>.
/// Use the <c>:header</c> pseudo-class to target the column header cell (row 0).
/// </summary> /// </summary>
public sealed class CalendarWeekNumberLabel : ContentControl public sealed class CalendarWeekNumberLabel : ContentControl
{ {
private bool _isHeader;
/// <summary>
/// Gets or sets a value indicating whether this label is the column header cell
/// (placed in row 0 of the month grid, above the week-number data cells).
/// Themes can target this with the <c>:header</c> pseudo-class.
/// </summary>
public bool IsHeader
{
get => _isHeader;
internal set
{
if (_isHeader == value) return;
_isHeader = value;
PseudoClasses.Set(":header", value);
}
}
} }
} }

4
src/Avalonia.Themes.Fluent/Accents/FluentControlResources.xaml

@ -402,6 +402,8 @@
<StaticResource x:Key="CalendarViewBorderBrush" ResourceKey="SystemControlForegroundChromeMediumBrush" /> <StaticResource x:Key="CalendarViewBorderBrush" ResourceKey="SystemControlForegroundChromeMediumBrush" />
<StaticResource x:Key="CalendarViewWeekDayForegroundDisabled" <StaticResource x:Key="CalendarViewWeekDayForegroundDisabled"
ResourceKey="SystemControlDisabledBaseMediumLowBrush" /> ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarViewWeekNumberSeparatorForeground"
ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarViewNavigationButtonBackground" ResourceKey="SystemControlTransparentBrush" /> <StaticResource x:Key="CalendarViewNavigationButtonBackground" ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="CalendarViewNavigationButtonForegroundPointerOver" <StaticResource x:Key="CalendarViewNavigationButtonForegroundPointerOver"
ResourceKey="SystemControlForegroundBaseHighBrush" /> ResourceKey="SystemControlForegroundBaseHighBrush" />
@ -1228,6 +1230,8 @@
<StaticResource x:Key="CalendarViewBorderBrush" ResourceKey="SystemControlForegroundChromeMediumBrush" /> <StaticResource x:Key="CalendarViewBorderBrush" ResourceKey="SystemControlForegroundChromeMediumBrush" />
<StaticResource x:Key="CalendarViewWeekDayForegroundDisabled" <StaticResource x:Key="CalendarViewWeekDayForegroundDisabled"
ResourceKey="SystemControlDisabledBaseMediumLowBrush" /> ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarViewWeekNumberSeparatorForeground"
ResourceKey="SystemControlDisabledBaseMediumLowBrush" />
<StaticResource x:Key="CalendarViewNavigationButtonBackground" ResourceKey="SystemControlTransparentBrush" /> <StaticResource x:Key="CalendarViewNavigationButtonBackground" ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="CalendarViewNavigationButtonForegroundPointerOver" <StaticResource x:Key="CalendarViewNavigationButtonForegroundPointerOver"
ResourceKey="SystemControlForegroundBaseHighBrush" /> ResourceKey="SystemControlForegroundBaseHighBrush" />

28
src/Avalonia.Themes.Fluent/Controls/CalendarWeekNumberLabel.xaml

@ -5,21 +5,35 @@
<ControlTheme x:Key="{x:Type CalendarWeekNumberLabel}" TargetType="CalendarWeekNumberLabel"> <ControlTheme x:Key="{x:Type CalendarWeekNumberLabel}" TargetType="CalendarWeekNumberLabel">
<Setter Property="MinWidth" Value="40" /> <Setter Property="MinWidth" Value="40" />
<Setter Property="MinHeight" Value="40" /> <Setter Property="MinHeight" Value="40" />
<Setter Property="Margin" Value="1" />
<Setter Property="Padding" Value="0" /> <Setter Property="Padding" Value="0" />
<Setter Property="Foreground" Value="{DynamicResource CalendarViewOutOfScopeForeground}" /> <Setter Property="Foreground" Value="{DynamicResource CalendarViewOutOfScopeForeground}" />
<Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource CalendarDayButtonFontSize}"></Setter>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<ContentPresenter Name="PART_ContentPresenter" <Border BorderBrush="{DynamicResource CalendarViewWeekNumberSeparatorForeground}"
ContentTemplate="{TemplateBinding ContentTemplate}" BorderThickness="0,0,1,0">
Content="{TemplateBinding Content}" <ContentPresenter Name="PART_ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" ContentTemplate="{TemplateBinding ContentTemplate}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}" /> HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}" />
</Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<!-- Header cell (row 0): match the day-of-week title row appearance -->
<Style Selector="^:header">
<Setter Property="MinHeight" Value="38" />
<Setter Property="MaxHeight" Value="38" />
<Setter Property="Padding" Value="0" />
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource CalendarViewForeground}" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>

30
src/Avalonia.Themes.Simple/Controls/CalendarWeekNumberLabel.xaml

@ -3,21 +3,35 @@
x:ClassModifier="internal"> x:ClassModifier="internal">
<ControlTheme x:Key="{x:Type CalendarWeekNumberLabel}" TargetType="CalendarWeekNumberLabel"> <ControlTheme x:Key="{x:Type CalendarWeekNumberLabel}" TargetType="CalendarWeekNumberLabel">
<Setter Property="Margin" Value="0,4,4,4" /> <Setter Property="Margin" Value="0,4,0,4" />
<Setter Property="Padding" Value="4,0" /> <Setter Property="Padding" Value="4,0,6,0" />
<Setter Property="FontSize" Value="9.5" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundLowBrush}" /> <Setter Property="Foreground" Value="{DynamicResource ThemeForegroundLowBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<ContentPresenter Name="PART_ContentPresenter" <Border BorderBrush="{DynamicResource ThemeBorderLowBrush}"
ContentTemplate="{TemplateBinding ContentTemplate}" BorderThickness="0,0,1,0">
Content="{TemplateBinding Content}" <ContentPresenter Name="PART_ContentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" ContentTemplate="{TemplateBinding ContentTemplate}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="{TemplateBinding Content}"
Margin="{TemplateBinding Padding}" /> HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="{TemplateBinding Padding}" />
</Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<!-- Header cell (row 0): match the DayTitleTemplate appearance (Bold, normal foreground) -->
<Style Selector="^:header">
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Padding" Value="4,0" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>

Loading…
Cancel
Save