misc: simplify EnumSelectorDemoViewModel.

This commit is contained in:
Zhang Dian
2025-05-19 20:08:50 +08:00
parent fd27a7d429
commit 2edfdee5df
2 changed files with 24 additions and 46 deletions

View File

@@ -26,7 +26,7 @@
EnumType="{Binding SelectedType}" EnumType="{Binding SelectedType}"
Value="{Binding Value}" /> Value="{Binding Value}" />
<TextBlock Text="{Binding Value}" /> <TextBlock Text="{Binding Value}" />
<u:Divider Content="Small Size"></u:Divider> <u:Divider Content="Small Size" />
<u:EnumSelector <u:EnumSelector
Width="200" Width="200"
Classes="Small" Classes="Small"

View File

@@ -11,55 +11,33 @@ using CommunityToolkit.Mvvm.ComponentModel;
namespace Ursa.Demo.ViewModels; namespace Ursa.Demo.ViewModels;
public class EnumSelectorDemoViewModel: ObservableObject public partial class EnumSelectorDemoViewModel : ObservableObject
{ {
public ObservableCollection<Type?> Types { get; set; } [ObservableProperty] private Type? _selectedType;
[ObservableProperty] private object? _value;
private Type? _selectedType; public ObservableCollection<Type?> Types { get; set; } =
public Type? SelectedType [
{ typeof(HorizontalAlignment),
get => _selectedType; typeof(VerticalAlignment),
set typeof(Orientation),
{ typeof(Dock),
SetProperty(ref _selectedType, value); typeof(GridResizeDirection),
Value = null; typeof(DayOfWeek),
} typeof(FillMode),
} typeof(IterationType),
typeof(BindingMode),
private object? _value; typeof(BindingPriority),
public object? Value typeof(StandardCursorType),
{ typeof(Key),
get => _value; typeof(KeyModifiers),
set => SetProperty(ref _value, value); typeof(RoutingStrategies),
} typeof(CustomEnum)
];
public EnumSelectorDemoViewModel()
{
Types = new ObservableCollection<Type?>()
{
typeof(HorizontalAlignment),
typeof(VerticalAlignment),
typeof(Orientation),
typeof(Dock),
typeof(GridResizeDirection),
typeof(DayOfWeek),
typeof(FillMode),
typeof(IterationType),
typeof(BindingMode),
typeof(BindingPriority),
typeof(StandardCursorType),
typeof(Key),
typeof(KeyModifiers),
typeof(RoutingStrategies),
typeof(CustomEnum),
};
}
} }
public enum CustomEnum public enum CustomEnum
{ {
[Description("是")] [Description("是")] Yes,
Yes, [Description("否")] No,
[Description("否")]
No,
} }