feat: optimize.

This commit is contained in:
Zhang Dian
2024-06-03 17:39:50 +08:00
parent ceede38804
commit f000c68597
5 changed files with 24 additions and 39 deletions

View File

@@ -2,29 +2,24 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<ControlTheme x:Key="{x:Type u:RatingCharacter}" TargetType="u:RatingCharacter">
<Setter Property="Foreground" Value="{DynamicResource RatingCharacterUnSelectedForeground}" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Foreground" Value="{DynamicResource RatingCharacterDefaultForeground}" />
<Setter Property="Background" Value="{DynamicResource RatingCharacterDefaultBackground}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<ControlTemplate TargetType="u:RatingCharacter">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<PathIcon Name="{x:Static u:RatingCharacter.PART_IconGlyph}"
Width="16"
Height="16"
Margin="4,0"
Data="{DynamicResource RatingStarUnSelectedIconGlyph}"
Foreground="{TemplateBinding Foreground}" />
<ToolTip.Tip>
<TextBlock Text="{Binding $parent[u:Rating].SelectedTooltip}" />
</ToolTip.Tip>
</Border>
<PathIcon Name="{x:Static u:RatingCharacter.PART_IconGlyph}"
Width="24"
Height="24"
Margin="0 0 6 0"
Data="{DynamicResource RatingStarIconGlyph}"
Foreground="{TemplateBinding Foreground}" />
</ControlTemplate>
</Setter>
<Style Selector="^:selected /template/ PathIcon#PART_IconGlyph">
<Setter Property="Data" Value="{DynamicResource RatingStarSelectedIconGlyph}" />
<Style Selector="^:pointerover">
<Setter Property="RenderTransform" Value="scale(1.1)" />
</Style>
<Style Selector="^:selected">
<Setter Property="Foreground" Value="{DynamicResource RatingCharacterSelectedForeground}" />
</Style>
</ControlTheme>
@@ -32,7 +27,7 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="ItemTemplate">
<DataTemplate>
<u:RatingCharacter Content="{Binding}" />
<u:RatingCharacter />
</DataTemplate>
</Setter>
<Setter Property="Template">

View File

@@ -1,4 +1,4 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="RatingCharacterDefaultForeground" Color="#FDDE43" />
<SolidColorBrush x:Key="RatingCharacterDefaultBackground" Color="Transparent" />
</ResourceDictionary>
<SolidColorBrush x:Key="RatingCharacterUnSelectedForeground" Opacity="0.12" Color="White" />
<SolidColorBrush x:Key="RatingCharacterSelectedForeground" Color="#FDDE43" />
</ResourceDictionary>

View File

@@ -1,4 +1,4 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="RatingCharacterDefaultForeground" Color="#FAC800" />
<SolidColorBrush x:Key="RatingCharacterDefaultBackground" Color="Transparent" />
</ResourceDictionary>
<SolidColorBrush x:Key="RatingCharacterUnSelectedForeground" Opacity="0.05" Color="#2E3238" />
<SolidColorBrush x:Key="RatingCharacterSelectedForeground" Color="#FAC800" />
</ResourceDictionary>

View File

@@ -1,5 +1,3 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<PathGeometry x:Key="RatingStarUnSelectedIconGlyph">M12 5.02863L9.56867 9.10197C9.39633 9.39072 9.10801 9.59094 8.77762 9.65133L4.47932 10.4369L7.47279 13.9041C7.69195 14.158 7.79145 14.494 7.74589 14.8265L7.13481 19.2864L11.5403 17.3919C11.8338 17.2657 12.1662 17.2657 12.4597 17.3919L16.8652 19.2864L16.2541 14.8265C16.2086 14.494 16.308 14.158 16.5272 13.9041L19.5207 10.4369L15.2224 9.65133C14.892 9.59095 14.6037 9.39072 14.4313 9.10198L12 5.02863ZM10.9998 2.56831C11.4521 1.81056 12.5479 1.81057 13.0002 2.56831L16.028 7.64098L21.5427 8.64887C22.4298 8.81101 22.8049 9.87773 22.215 10.561L18.4119 14.9659L19.1938 20.672C19.3171 21.5718 18.4126 22.2617 17.5795 21.9035L12 19.5041L6.4205 21.9035C5.58741 22.2617 4.68294 21.5718 4.80622 20.672L5.58806 14.9659L1.78503 10.561C1.19513 9.87772 1.57018 8.81101 2.45731 8.64887L7.97197 7.64098L10.9998 2.56831Z</PathGeometry>
<PathGeometry x:Key="RatingStarSelectedIconGlyph">M10.7525 1.90411C11.1451 0.698628 12.8549 0.698631 13.2475 1.90411L15.2395 8.01946H21.6858C22.9565 8.01946 23.4848 9.64143 22.4568 10.3865L17.2417 14.1659L19.2337 20.2813C19.6263 21.4868 18.2431 22.4892 17.2151 21.7442L12 17.9647L6.78489 21.7442C5.75687 22.4892 4.37368 21.4868 4.76635 20.2813L6.75834 14.1659L1.54323 10.3865C0.515206 9.64142 1.04354 8.01946 2.31425 8.01946H8.76048L10.7525 1.90411Z</PathGeometry>
</ResourceDictionary>
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<PathGeometry x:Key="RatingStarIconGlyph">M10.7525 1.90411C11.1451 0.698628 12.8549 0.698631 13.2475 1.90411L15.2395 8.01946H21.6858C22.9565 8.01946 23.4848 9.64143 22.4568 10.3865L17.2417 14.1659L19.2337 20.2813C19.6263 21.4868 18.2431 22.4892 17.2151 21.7442L12 17.9647L6.78489 21.7442C5.75687 22.4892 4.37368 21.4868 4.76635 20.2813L6.75834 14.1659L1.54323 10.3865C0.515206 9.64142 1.04354 8.01946 2.31425 8.01946H8.76048L10.7525 1.90411Z</PathGeometry>
</ResourceDictionary>

View File

@@ -8,19 +8,11 @@ namespace Ursa.Controls;
[PseudoClasses(PC_Selected)]
[TemplatePart(PART_IconGlyph, typeof(PathIcon))]
public class RatingCharacter : ContentControl
public class RatingCharacter : TemplatedControl
{
public const string PART_IconGlyph = "PART_IconGlyph";
protected const string PC_Selected = ":selected";
private PathIcon? _icon;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_icon = e.NameScope.Find<PathIcon>(PART_IconGlyph);
}
protected override void OnPointerEntered(PointerEventArgs e)
{
var parent = this.GetLogicalAncestors().OfType<Rating>().FirstOrDefault();