2023-02-12 00:56:45 +08:00
|
|
|
using Avalonia;
|
|
|
|
|
using Avalonia.Controls.Primitives;
|
|
|
|
|
using Avalonia.Input;
|
|
|
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
|
|
|
using Semi.Avalonia.Demo.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace Semi.Avalonia.Demo.Controls;
|
|
|
|
|
|
|
|
|
|
public class ColorItemControl : TemplatedControl
|
|
|
|
|
{
|
2024-12-24 16:39:57 +08:00
|
|
|
public static readonly StyledProperty<string?> ColorNameProperty =
|
|
|
|
|
AvaloniaProperty.Register<ColorItemControl, string?>(nameof(ColorName));
|
2023-02-12 00:56:45 +08:00
|
|
|
|
|
|
|
|
public string? ColorName
|
|
|
|
|
{
|
|
|
|
|
get => GetValue(ColorNameProperty);
|
|
|
|
|
set => SetValue(ColorNameProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static readonly StyledProperty<string?> HexProperty = AvaloniaProperty.Register<ColorItemControl, string?>(
|
|
|
|
|
nameof(Hex));
|
|
|
|
|
|
|
|
|
|
public string? Hex
|
|
|
|
|
{
|
|
|
|
|
get => GetValue(HexProperty);
|
|
|
|
|
set => SetValue(HexProperty, value);
|
|
|
|
|
}
|
2024-12-24 16:39:57 +08:00
|
|
|
|
2023-02-12 00:56:45 +08:00
|
|
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnPointerPressed(e);
|
2024-12-24 16:39:57 +08:00
|
|
|
switch (this.DataContext)
|
2023-02-12 00:56:45 +08:00
|
|
|
{
|
2024-12-24 16:39:57 +08:00
|
|
|
case ColorItemViewModel colorItemViewModel:
|
|
|
|
|
WeakReferenceMessenger.Default.Send(colorItemViewModel);
|
|
|
|
|
break;
|
|
|
|
|
case ColorResource colorResource:
|
|
|
|
|
WeakReferenceMessenger.Default.Send(colorResource);
|
|
|
|
|
break;
|
2023-02-12 00:56:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|