From 34568a4af853a964c0cc60f6a6dfb8aa44c15907 Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Fri, 7 Jun 2024 10:52:35 +0800
Subject: [PATCH] feat: add property Character.
---
demo/Ursa.Demo/Pages/RatingDemo.axaml | 25 ++++++++++++-----
src/Ursa.Themes.Semi/Controls/Rating.axaml | 10 +++----
.../Themes/Shared/Rating.axaml | 2 +-
src/Ursa/Controls/Rating/Rating.cs | 27 ++++++++++---------
src/Ursa/Controls/Rating/RatingCharacter.cs | 9 +++++++
5 files changed, 48 insertions(+), 25 deletions(-)
diff --git a/demo/Ursa.Demo/Pages/RatingDemo.axaml b/demo/Ursa.Demo/Pages/RatingDemo.axaml
index dadcd77..f2b4af0 100644
--- a/demo/Ursa.Demo/Pages/RatingDemo.axaml
+++ b/demo/Ursa.Demo/Pages/RatingDemo.axaml
@@ -10,19 +10,32 @@
x:CompileBindings="True"
x:DataType="vm:RatingDemoViewModel"
mc:Ignorable="d">
+
+
+ M12 5.99999C10.5 2.12432 5.75193 2.0557 3.40383 4.4038C0.865423 6.94221 0.999999 10.5 3.50001 14C5.52139 16.8299 9.83088 20.3136 11.4069 21.5438C11.7573 21.8172 12.2427 21.8172 12.5931 21.5438C14.1691 20.3136 18.4786 16.8299 20.5 14C23 10.5 23.1346 6.94221 20.5962 4.4038C18.2481 2.0557 14.5 2.12432 12 5.99999Z
+
+
-
+
+ DefaultValue="{Binding DefaultValue}" />
+
diff --git a/src/Ursa.Themes.Semi/Controls/Rating.axaml b/src/Ursa.Themes.Semi/Controls/Rating.axaml
index 0e84c51..25e8e4d 100644
--- a/src/Ursa.Themes.Semi/Controls/Rating.axaml
+++ b/src/Ursa.Themes.Semi/Controls/Rating.axaml
@@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
-
+
@@ -12,14 +12,14 @@
@@ -36,6 +36,8 @@
+
+
@@ -45,8 +47,6 @@
- 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
+ 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
\ No newline at end of file
diff --git a/src/Ursa/Controls/Rating/Rating.cs b/src/Ursa/Controls/Rating/Rating.cs
index af8bee4..08ece69 100644
--- a/src/Ursa/Controls/Rating/Rating.cs
+++ b/src/Ursa/Controls/Rating/Rating.cs
@@ -115,6 +115,7 @@ public class Rating : TemplatedControl
private void OnValueChanged(AvaloniaPropertyChangedEventArgs e)
{
+ if (!IsLoaded) return;
if (e.NewValue is double newValue)
{
UpdateItemsByValue(newValue);
@@ -133,7 +134,11 @@ public class Rating : TemplatedControl
var itemsToAdd = newCount - currentCount;
for (var i = 0; i < itemsToAdd; i++)
{
- Items.Add(new RatingCharacter());
+ Items.Add(new RatingCharacter
+ {
+ Character = Character,
+ AllowHalf = AllowHalf
+ });
}
}
else if (currentCount > newCount)
@@ -145,11 +150,6 @@ public class Rating : TemplatedControl
}
}
- foreach (var item in Items)
- {
- item.AllowHalf = AllowHalf;
- }
-
UpdateItemsByValue(Value);
}
@@ -171,26 +171,27 @@ public class Rating : TemplatedControl
_itemsControl = e.NameScope.Find(PART_ItemsControl);
for (var i = 0; i < Count; i++)
{
- Items.Add(new RatingCharacter());
- }
-
- foreach (var item in Items)
- {
- item.AllowHalf = AllowHalf;
+ Items.Add(new RatingCharacter
+ {
+ Character = Character,
+ AllowHalf = AllowHalf
+ }
+ );
}
SetCurrentValue(ValueProperty, DefaultValue);
+ UpdateItemsByValue(DefaultValue);
}
internal void PointerEnteredHandler(RatingCharacter o)
{
- var index = Items.IndexOf(o);
var item = Items.FirstOrDefault(item => item.IsLast);
if (item is not null)
{
item.IsHalf = false;
}
+ var index = Items.IndexOf(o);
UpdateItemsByIndex(index);
}
diff --git a/src/Ursa/Controls/Rating/RatingCharacter.cs b/src/Ursa/Controls/Rating/RatingCharacter.cs
index 1ae89d2..0bfaddc 100644
--- a/src/Ursa/Controls/Rating/RatingCharacter.cs
+++ b/src/Ursa/Controls/Rating/RatingCharacter.cs
@@ -20,12 +20,21 @@ public class RatingCharacter : TemplatedControl
public static readonly StyledProperty AllowHalfProperty =
Rating.AllowHalfProperty.AddOwner();
+ public static readonly StyledProperty