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