Revert "fix: Cannot set Background for default SolidButton theme"

This reverts commit 054b6f59d5.
This commit is contained in:
snail1519
2025-03-18 11:30:03 +08:00
parent 054b6f59d5
commit ccdbf25004
3 changed files with 6 additions and 52 deletions

View File

@@ -52,7 +52,6 @@
<Button Classes="Success" Theme="{DynamicResource SolidButton}">Success</Button>
<Button Classes="Warning" Theme="{DynamicResource SolidButton}">Warning</Button>
<Button Classes="Danger" Theme="{DynamicResource SolidButton}">Danger</Button>
<Button Background="Purple" BorderBrush="Purple" Theme="{DynamicResource SolidButton}">Custom</Button>
<Button
Classes="Danger"
IsEnabled="False"

View File

@@ -1,7 +1,6 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:semiConverters="clr-namespace:Semi.Avalonia.Converters"
x:CompileBindings="True">
<!-- Button Theme Key: Light, Solid, Outline, Borderless; Default is Light -->
<!-- Button Default Classes: Primary, Secondary, Tertiary, Success, Warning, Danger; Default is Primary -->
@@ -98,8 +97,6 @@
<Setter Property="Padding" Value="{DynamicResource ButtonSmallPadding}" />
</Style>
</ControlTheme>
<semiConverters:AdaptiveColorConverter x:Key="AdaptiveColorConverter"/>
<ControlTheme
x:Key="SolidButton"
@@ -111,22 +108,20 @@
Classes="Solid" />
</FocusAdornerTemplate>
</Setter>
<Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryBorderBrush}" />
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonSolidForeground}" />
<Setter Property="Background" Value="{TemplateBinding Background}" />
<Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush}" />
<Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryBorderBrush}" />
</Style>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{TemplateBinding Background, Converter={StaticResource AdaptiveColorConverter}, ConverterParameter=0.2}" />
<Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush, Converter={StaticResource AdaptiveColorConverter}, ConverterParameter=0.2}" />
<Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPointeroverBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPointeroverBorderBrush}" />
</Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ButtonSolidPrimaryPressedForeground}" />
<Setter Property="Background" Value="{TemplateBinding Background, Converter={StaticResource AdaptiveColorConverter}, ConverterParameter=0.4}" />
<Setter Property="BorderBrush" Value="{TemplateBinding BorderBrush, Converter={StaticResource AdaptiveColorConverter}, ConverterParameter=0.4}" />
<Setter Property="Background" Value="{DynamicResource ButtonSolidPrimaryPressedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonSolidPrimaryPressedBorderBrush}" />
</Style>
<Style Selector="^.Primary">

View File

@@ -1,40 +0,0 @@
using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
using Avalonia.Media.Immutable;
using Avalonia.Styling;
namespace Semi.Avalonia.Converters;
public class AdaptiveColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is IImmutableSolidColorBrush brush)
{
var color = brush.Color;
var theme = Application.Current.ActualThemeVariant;
var para = double.Parse(parameter?.ToString() ?? "0.2");
double factor = theme == ThemeVariant.Light ? -para : para;
return AdjustColorBrightness(color, factor);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
private IImmutableSolidColorBrush AdjustColorBrightness(Color color, double factor)
{
// 调整颜色亮度
var r = (byte)Math.Min(255, Math.Max(0, color.R + color.R * factor));
var g = (byte)Math.Min(255, Math.Max(0, color.G + color.G * factor));
var b = (byte)Math.Min(255, Math.Max(0, color.B + color.B * factor));
return new ImmutableSolidColorBrush(Color.FromRgb(r, g, b));
}
}