feat: add property Size.
This commit is contained in:
@@ -28,6 +28,16 @@
|
|||||||
Count="{Binding Count}"
|
Count="{Binding Count}"
|
||||||
DefaultValue="{Binding DefaultValue}" />
|
DefaultValue="{Binding DefaultValue}" />
|
||||||
<u:Rating
|
<u:Rating
|
||||||
|
Classes="Small"
|
||||||
|
AllowClear="{Binding AllowClear}"
|
||||||
|
AllowHalf="{Binding AllowHalf}"
|
||||||
|
AllowFocus="{Binding AllowFocus}"
|
||||||
|
IsEnabled="{Binding IsEnabled}"
|
||||||
|
Value="{Binding Value}"
|
||||||
|
Count="{Binding Count}"
|
||||||
|
DefaultValue="{Binding DefaultValue}" />
|
||||||
|
<u:Rating
|
||||||
|
Size="48"
|
||||||
AllowClear="{Binding AllowClear}"
|
AllowClear="{Binding AllowClear}"
|
||||||
AllowHalf="{Binding AllowHalf}"
|
AllowHalf="{Binding AllowHalf}"
|
||||||
AllowFocus="{Binding AllowFocus}"
|
AllowFocus="{Binding AllowFocus}"
|
||||||
@@ -40,7 +50,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Border Grid.Column="1" VerticalAlignment="Top">
|
<Border Grid.Column="1" VerticalAlignment="Top">
|
||||||
<Grid ColumnDefinitions="*, Auto" RowDefinitions="*,*,*,*,*,*,*">
|
<Grid ColumnDefinitions="*, Auto" RowDefinitions="*,*,*,*,*,*,*,*">
|
||||||
<Label
|
<Label
|
||||||
Grid.Row="0"
|
Grid.Row="0"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ public partial class RatingDemoViewModel : ViewModelBase
|
|||||||
|
|
||||||
[ObservableProperty] private double _value;
|
[ObservableProperty] private double _value;
|
||||||
|
|
||||||
// [ObservableProperty] private object _character;
|
|
||||||
[ObservableProperty] private int _count = 5;
|
|
||||||
[ObservableProperty] private double _defaultValue = 2.3;
|
[ObservableProperty] private double _defaultValue = 2.3;
|
||||||
|
[ObservableProperty] private int _count = 5;
|
||||||
|
// [ObservableProperty] private object _character;
|
||||||
|
|
||||||
public ObservableCollection<string> Tooltips { get; set; } = ["1", "2", "3", "4", "5"];
|
public ObservableCollection<string> Tooltips { get; set; } = ["1", "2", "3", "4", "5"];
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,13 @@
|
|||||||
<Setter Property="Character" Value="{DynamicResource RatingStarIconGlyph}" />
|
<Setter Property="Character" Value="{DynamicResource RatingStarIconGlyph}" />
|
||||||
<Setter Property="Background" Value="{DynamicResource RatingCharacterBackground}" />
|
<Setter Property="Background" Value="{DynamicResource RatingCharacterBackground}" />
|
||||||
<Setter Property="Cursor" Value="Hand" />
|
<Setter Property="Cursor" Value="Hand" />
|
||||||
<Setter Property="Margin" Value="3,4" />
|
<Setter Property="Margin" Value="{DynamicResource RatingCharacterMargin}" />
|
||||||
<Setter Property="VerticalAlignment" Value="Stretch" />
|
<Setter Property="VerticalAlignment" Value="Stretch" />
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<ControlTemplate TargetType="u:RatingCharacter">
|
<ControlTemplate TargetType="u:RatingCharacter">
|
||||||
<Canvas Name="PART_Root" Width="24" Height="24">
|
<Canvas Name="PART_Root"
|
||||||
|
Width="{TemplateBinding Size}"
|
||||||
|
Height="{TemplateBinding Size}">
|
||||||
<Path Width="{Binding #PART_Root.Width}"
|
<Path Width="{Binding #PART_Root.Width}"
|
||||||
Height="{Binding #PART_Root.Height}"
|
Height="{Binding #PART_Root.Height}"
|
||||||
Stretch="Uniform"
|
Stretch="Uniform"
|
||||||
@@ -39,6 +41,7 @@
|
|||||||
<ControlTheme x:Key="{x:Type u:Rating}" TargetType="u:Rating">
|
<ControlTheme x:Key="{x:Type u:Rating}" TargetType="u:Rating">
|
||||||
<Setter Property="Foreground" Value="{DynamicResource RatingCharacterForeground}" />
|
<Setter Property="Foreground" Value="{DynamicResource RatingCharacterForeground}" />
|
||||||
<Setter Property="Character" Value="{DynamicResource RatingStarIconGlyph}" />
|
<Setter Property="Character" Value="{DynamicResource RatingStarIconGlyph}" />
|
||||||
|
<Setter Property="Size" Value="{DynamicResource RatingDefaultSize}" />
|
||||||
<Setter Property="ItemTemplate">
|
<Setter Property="ItemTemplate">
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<u:RatingCharacter />
|
<u:RatingCharacter />
|
||||||
@@ -68,5 +71,8 @@
|
|||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
<Style Selector="^.Small">
|
||||||
|
<Setter Property="Size" Value="{DynamicResource RatingSmallSize}" />
|
||||||
|
</Style>
|
||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
|
<x:Double x:Key="RatingDefaultSize">24</x:Double>
|
||||||
|
<x:Double x:Key="RatingSmallSize">16</x:Double>
|
||||||
|
<Thickness x:Key="RatingCharacterMargin">3 4</Thickness>
|
||||||
<StreamGeometry 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</StreamGeometry>
|
<StreamGeometry 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</StreamGeometry>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
@@ -38,6 +38,9 @@ public class Rating : TemplatedControl
|
|||||||
public static readonly StyledProperty<double> DefaultValueProperty =
|
public static readonly StyledProperty<double> DefaultValueProperty =
|
||||||
AvaloniaProperty.Register<Rating, double>(nameof(DefaultValue));
|
AvaloniaProperty.Register<Rating, double>(nameof(DefaultValue));
|
||||||
|
|
||||||
|
public static readonly StyledProperty<double> SizeProperty =
|
||||||
|
AvaloniaProperty.Register<RatingCharacter, double>(nameof(Size));
|
||||||
|
|
||||||
public static readonly StyledProperty<IDataTemplate?> ItemTemplateProperty =
|
public static readonly StyledProperty<IDataTemplate?> ItemTemplateProperty =
|
||||||
AvaloniaProperty.Register<Rating, IDataTemplate?>(nameof(ItemTemplate));
|
AvaloniaProperty.Register<Rating, IDataTemplate?>(nameof(ItemTemplate));
|
||||||
|
|
||||||
@@ -83,6 +86,12 @@ public class Rating : TemplatedControl
|
|||||||
set => SetValue(DefaultValueProperty, value);
|
set => SetValue(DefaultValueProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double Size
|
||||||
|
{
|
||||||
|
get => GetValue(SizeProperty);
|
||||||
|
set => SetValue(SizeProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public IDataTemplate? ItemTemplate
|
public IDataTemplate? ItemTemplate
|
||||||
{
|
{
|
||||||
get => GetValue(ItemTemplateProperty);
|
get => GetValue(ItemTemplateProperty);
|
||||||
@@ -137,7 +146,8 @@ public class Rating : TemplatedControl
|
|||||||
Items.Add(new RatingCharacter
|
Items.Add(new RatingCharacter
|
||||||
{
|
{
|
||||||
Character = Character,
|
Character = Character,
|
||||||
AllowHalf = AllowHalf
|
AllowHalf = AllowHalf,
|
||||||
|
Size = Size,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +184,8 @@ public class Rating : TemplatedControl
|
|||||||
Items.Add(new RatingCharacter
|
Items.Add(new RatingCharacter
|
||||||
{
|
{
|
||||||
Character = Character,
|
Character = Character,
|
||||||
AllowHalf = AllowHalf
|
AllowHalf = AllowHalf,
|
||||||
|
Size = Size,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ public class RatingCharacter : TemplatedControl
|
|||||||
public static readonly StyledProperty<object> CharacterProperty =
|
public static readonly StyledProperty<object> CharacterProperty =
|
||||||
Rating.CharacterProperty.AddOwner<RatingCharacter>();
|
Rating.CharacterProperty.AddOwner<RatingCharacter>();
|
||||||
|
|
||||||
|
public static readonly StyledProperty<double> SizeProperty =
|
||||||
|
Rating.SizeProperty.AddOwner<RatingCharacter>();
|
||||||
|
|
||||||
public bool AllowHalf
|
public bool AllowHalf
|
||||||
{
|
{
|
||||||
get => GetValue(AllowHalfProperty);
|
get => GetValue(AllowHalfProperty);
|
||||||
@@ -35,6 +38,12 @@ public class RatingCharacter : TemplatedControl
|
|||||||
set => SetValue(CharacterProperty, value);
|
set => SetValue(CharacterProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double Size
|
||||||
|
{
|
||||||
|
get => GetValue(SizeProperty);
|
||||||
|
set => SetValue(SizeProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
internal bool IsLast { get; set; }
|
internal bool IsLast { get; set; }
|
||||||
|
|
||||||
private bool _isHalf;
|
private bool _isHalf;
|
||||||
|
|||||||
Reference in New Issue
Block a user