feat: add pseudoclasses.
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
<Setter Property="u:DualBadge.Foreground" Value="{DynamicResource DualBadgeDefaultForeground}" />
|
<Setter Property="u:DualBadge.Foreground" Value="{DynamicResource DualBadgeDefaultForeground}" />
|
||||||
<Setter Property="u:DualBadge.Background" Value="{DynamicResource DualBadgeDefaultBackground}" />
|
<Setter Property="u:DualBadge.Background" Value="{DynamicResource DualBadgeDefaultBackground}" />
|
||||||
<Setter Property="u:DualBadge.ClipToBounds" Value="False" />
|
<Setter Property="u:DualBadge.ClipToBounds" Value="False" />
|
||||||
<Setter Property="u:DualBadge.HorizontalAlignment" Value="Center" />
|
<Setter Property="u:DualBadge.HorizontalAlignment" Value="Left" />
|
||||||
<Setter Property="u:DualBadge.VerticalAlignment" Value="Center" />
|
<Setter Property="u:DualBadge.VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="u:DualBadge.UseLayoutRounding" Value="False" />
|
<Setter Property="u:DualBadge.UseLayoutRounding" Value="False" />
|
||||||
<Setter Property="u:DualBadge.Padding" Value="{DynamicResource DualBadgeDefaultPadding}" />
|
<Setter Property="u:DualBadge.Padding" Value="{DynamicResource DualBadgeDefaultPadding}" />
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||||
ClipToBounds="True"
|
ClipToBounds="True"
|
||||||
CornerRadius="{TemplateBinding CornerRadius}">
|
CornerRadius="{TemplateBinding CornerRadius}">
|
||||||
<Grid ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="Auto,Auto">
|
||||||
<DockPanel
|
<DockPanel
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
Background="{TemplateBinding HeaderBackground}">
|
Background="{TemplateBinding HeaderBackground}">
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
Foreground="{TemplateBinding HeaderForeground}"
|
Foreground="{TemplateBinding HeaderForeground}"
|
||||||
Padding="{TemplateBinding Padding}"
|
Padding="{TemplateBinding Padding}"
|
||||||
Content="{TemplateBinding Header}"
|
Content="{TemplateBinding Header}"
|
||||||
ContentTemplate="{TemplateBinding HeaderTemplate}"/>
|
ContentTemplate="{TemplateBinding HeaderTemplate}" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
Name="{x:Static u:DualBadge.PART_ContentPresenter}"
|
Name="{x:Static u:DualBadge.PART_ContentPresenter}"
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
</Setter>
|
</Setter>
|
||||||
|
|
||||||
<Style Selector="^:header-empty">
|
<Style Selector="^:header-empty">
|
||||||
<Setter Property="HeaderBackground" Value="LightGreen" />
|
<Setter Property="HeaderBackground" Value="{Binding Background, RelativeSource={RelativeSource Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -4,6 +4,7 @@ using Avalonia.Controls.Metadata;
|
|||||||
using Avalonia.Controls.Presenters;
|
using Avalonia.Controls.Presenters;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
@@ -64,56 +65,33 @@ public class DualBadge : HeaderedContentControl
|
|||||||
set => SetValue(HeaderBackgroundProperty, value);
|
set => SetValue(HeaderBackgroundProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsIconEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
|
|
||||||
nameof(IsIconEmpty));
|
|
||||||
|
|
||||||
public bool IsIconEmpty
|
|
||||||
{
|
|
||||||
get => GetValue(IsIconEmptyProperty);
|
|
||||||
set => SetValue(IsIconEmptyProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsHeaderEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
|
|
||||||
nameof(IsHeaderEmpty));
|
|
||||||
|
|
||||||
public bool IsHeaderEmpty
|
|
||||||
{
|
|
||||||
get => GetValue(IsHeaderEmptyProperty);
|
|
||||||
set => SetValue(IsHeaderEmptyProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsContentEmptyProperty = AvaloniaProperty.Register<DualBadge, bool>(
|
|
||||||
nameof(IsContentEmpty));
|
|
||||||
|
|
||||||
public bool IsContentEmpty
|
|
||||||
{
|
|
||||||
get => GetValue(IsContentEmptyProperty);
|
|
||||||
set => SetValue(IsContentEmptyProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static DualBadge()
|
static DualBadge()
|
||||||
{
|
{
|
||||||
IsIconEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsIconEmptyChanged(e));
|
IconProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnIconChanged());
|
||||||
IsHeaderEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsHeaderEmptyChanged(e));
|
HeaderProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnHeaderChanged());
|
||||||
IsContentEmptyProperty.Changed.AddClassHandler<DualBadge>((o, e) => o.OnIsContentEmptyChanged(e));
|
ContentProperty.Changed.AddClassHandler<DualBadge>((o, args) => o.OnContentChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIsIconEmptyChanged(AvaloniaPropertyChangedEventArgs args)
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
bool newValue = args.GetNewValue<bool>();
|
base.OnLoaded(e);
|
||||||
PseudoClasses.Set(PC_IconEmpty, newValue);
|
OnIconChanged();
|
||||||
|
OnHeaderChanged();
|
||||||
|
OnContentChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIsHeaderEmptyChanged(AvaloniaPropertyChangedEventArgs args)
|
private void OnIconChanged()
|
||||||
{
|
{
|
||||||
bool newValue = args.GetNewValue<bool>();
|
PseudoClasses.Set(PC_IconEmpty, Icon is null);
|
||||||
PseudoClasses.Set(PC_HeaderEmpty, newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIsContentEmptyChanged(AvaloniaPropertyChangedEventArgs args)
|
private void OnHeaderChanged()
|
||||||
{
|
{
|
||||||
bool newValue = args.GetNewValue<bool>();
|
PseudoClasses.Set(PC_HeaderEmpty, Header is null);
|
||||||
PseudoClasses.Set(PC_ContentEmpty, newValue);
|
}
|
||||||
|
|
||||||
|
private void OnContentChanged()
|
||||||
|
{
|
||||||
|
PseudoClasses.Set(PC_ContentEmpty, Content is null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user