feat: add property Character.

This commit is contained in:
Zhang Dian
2024-06-07 10:52:35 +08:00
parent e5628f7f23
commit 34568a4af8
5 changed files with 48 additions and 25 deletions

View File

@@ -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<ItemsControl>(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);
}