feat: initialize and setup demo.
This commit is contained in:
@@ -8,6 +8,7 @@ public static class MenuKeys
|
||||
public const string MenuKeyButtonGroup = "ButtonGroup";
|
||||
public const string MenuKeyDivider = "Divider";
|
||||
public const string MenuKeyDualBadge = "DualBadge";
|
||||
public const string MenuKeyEnumSelector = "EnumSelector";
|
||||
public const string MenuKeyImageViewer = "ImageViewer";
|
||||
public const string MenuKeyIpBox = "IPv4Box";
|
||||
public const string MenuKeyIconButton = "IconButton";
|
||||
|
||||
19
demo/Ursa.Demo/Pages/EnumSelectorDemo.axaml
Normal file
19
demo/Ursa.Demo/Pages/EnumSelectorDemo.axaml
Normal file
@@ -0,0 +1,19 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
x:DataType="vm:EnumSelectorDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Pages.EnumSelectorDemo">
|
||||
<StackPanel>
|
||||
<TextBlock Text="Select Type"></TextBlock>
|
||||
<ComboBox ItemsSource="{Binding Types}" DisplayMemberBinding="{Binding Name}" SelectedItem="{Binding SelectedType}"/>
|
||||
<TextBlock Text="Select Value"></TextBlock>
|
||||
<u:EnumSelector EnumType="{Binding SelectedType}" Value="{Binding Value}" />
|
||||
<TextBlock Text="{Binding Value}"></TextBlock>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
13
demo/Ursa.Demo/Pages/EnumSelectorDemo.axaml.cs
Normal file
13
demo/Ursa.Demo/Pages/EnumSelectorDemo.axaml.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Ursa.Demo.Pages;
|
||||
|
||||
public partial class EnumSelectorDemo : UserControl
|
||||
{
|
||||
public EnumSelectorDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
55
demo/Ursa.Demo/ViewModels/EnumSelectorDemoViewModel.cs
Normal file
55
demo/Ursa.Demo/ViewModels/EnumSelectorDemoViewModel.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public class EnumSelectorDemoViewModel: ObservableObject
|
||||
{
|
||||
public ObservableCollection<Type?> Types { get; set; }
|
||||
|
||||
private Type? _selectedType;
|
||||
public Type? SelectedType
|
||||
{
|
||||
get => _selectedType;
|
||||
set
|
||||
{
|
||||
SetProperty(ref _selectedType, value);
|
||||
Value = null;
|
||||
}
|
||||
}
|
||||
|
||||
private object? _value;
|
||||
public object? Value
|
||||
{
|
||||
get => _value;
|
||||
set => SetProperty(ref _value, value);
|
||||
}
|
||||
|
||||
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),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class MainViewViewModel : ViewModelBase
|
||||
MenuKeys.MenuKeyButtonGroup => new ButtonGroupDemoViewModel(),
|
||||
MenuKeys.MenuKeyDivider => new DividerDemoViewModel(),
|
||||
MenuKeys.MenuKeyDualBadge => new DualBadgeDemoViewModel(),
|
||||
MenuKeys.MenuKeyEnumSelector => new EnumSelectorDemoViewModel(),
|
||||
MenuKeys.MenuKeyImageViewer => new ImageViewerDemoViewModel(),
|
||||
MenuKeys.MenuKeyIconButton => new IconButtonDemoViewModel(),
|
||||
MenuKeys.MenuKeyIpBox => new IPv4BoxDemoViewModel(),
|
||||
|
||||
@@ -17,6 +17,7 @@ public class MenuViewModel: ViewModelBase
|
||||
new() { MenuHeader = "ButtonGroup", Key = MenuKeys.MenuKeyButtonGroup },
|
||||
new() { MenuHeader = "Divider", Key = MenuKeys.MenuKeyDivider },
|
||||
new() { MenuHeader = "DualBadge", Key = MenuKeys.MenuKeyDualBadge },
|
||||
new() { MenuHeader = "Enum Selector", Key = MenuKeys.MenuKeyEnumSelector },
|
||||
new() { MenuHeader = "IconButton", Key = MenuKeys.MenuKeyIconButton },
|
||||
new() { MenuHeader = "ImageViewer", Key = MenuKeys.MenuKeyImageViewer },
|
||||
new() { MenuHeader = "IPv4Box", Key = MenuKeys.MenuKeyIpBox },
|
||||
|
||||
13
src/Ursa.Themes.Semi/Controls/EnumSelector.axaml
Normal file
13
src/Ursa.Themes.Semi/Controls/EnumSelector.axaml
Normal file
@@ -0,0 +1,13 @@
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
<!-- Add Resources Here -->
|
||||
<ControlTheme x:Key="{x:Type u:EnumSelector}" TargetType="u:EnumSelector">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:EnumSelector">
|
||||
<ComboBox ItemsSource="{TemplateBinding Values}" SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
@@ -6,6 +6,7 @@
|
||||
<ResourceInclude Source="ButtonGroup.axaml" />
|
||||
<ResourceInclude Source="Divider.axaml" />
|
||||
<ResourceInclude Source="DualBadge.axaml" />
|
||||
<ResourceInclude Source="EnumSelector.axaml" />
|
||||
<ResourceInclude Source="IconButton.axaml" />
|
||||
<ResourceInclude Source="ImageViewer.axaml" />
|
||||
<ResourceInclude Source="IPv4Box.axaml" />
|
||||
|
||||
67
src/Ursa/Controls/EnumSelector/EnumSelector.cs
Normal file
67
src/Ursa/Controls/EnumSelector/EnumSelector.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class EnumSelector: TemplatedControl
|
||||
{
|
||||
public static readonly StyledProperty<Type?> EnumTypeProperty = AvaloniaProperty.Register<EnumSelector, Type?>(
|
||||
nameof(EnumType), validate: OnTypeValidate);
|
||||
|
||||
public Type? EnumType
|
||||
{
|
||||
get => GetValue(EnumTypeProperty);
|
||||
set => SetValue(EnumTypeProperty, value);
|
||||
}
|
||||
|
||||
private static bool OnTypeValidate(Type? arg)
|
||||
{
|
||||
if (arg is null) return true;
|
||||
return arg.IsEnum;
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<object?> ValueProperty = AvaloniaProperty.Register<EnumSelector, object?>(
|
||||
nameof(Value), defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
public object? Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<EnumSelector, IList<object?>?> ValuesProperty = AvaloniaProperty.RegisterDirect<EnumSelector, IList<object?>?>(
|
||||
nameof(Values), o => o.Values);
|
||||
|
||||
private IList<object?>? _values;
|
||||
internal IList<object?>? Values
|
||||
{
|
||||
get => _values;
|
||||
private set => SetAndRaise(ValuesProperty, ref _values, value);
|
||||
}
|
||||
|
||||
|
||||
static EnumSelector()
|
||||
{
|
||||
EnumTypeProperty.Changed.AddClassHandler<EnumSelector, Type?>((o, e) => o.OnTypeChanged(e));
|
||||
}
|
||||
|
||||
private void OnTypeChanged(AvaloniaPropertyChangedEventArgs<Type?> args)
|
||||
{
|
||||
var newType = args.GetNewValue<Type?>();
|
||||
if (newType is null || !newType.IsEnum)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var values = Enum.GetValues(newType);
|
||||
List<object?> list = new();
|
||||
foreach (var value in values)
|
||||
{
|
||||
if (value.GetType() == newType)
|
||||
list.Add(value);
|
||||
}
|
||||
Values = list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user