diff --git a/demo/Semi.Avalonia.Demo.Desktop/App.axaml b/demo/Semi.Avalonia.Demo.Desktop/App.axaml index cb85fcd..9628b3e 100644 --- a/demo/Semi.Avalonia.Demo.Desktop/App.axaml +++ b/demo/Semi.Avalonia.Demo.Desktop/App.axaml @@ -2,7 +2,8 @@ x:Class="Semi.Avalonia.Demo.Desktop.App" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="using:Semi.Avalonia.Demo.Desktop"> + xmlns:local="using:Semi.Avalonia.Demo.Desktop" + RequestedThemeVariant="Dark"> diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml index b0206c4..7ec3669 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml @@ -4,31 +4,68 @@ 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" + xmlns:viewModels="clr-namespace:Semi.Avalonia.Demo.ViewModels" d:DesignHeight="450" d:DesignWidth="800" mc:Ignorable="d"> + + + - - - - - - + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs index d9c359b..321e719 100644 --- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs +++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; +using Semi.Avalonia.Demo.ViewModels; namespace Semi.Avalonia.Demo.Pages; @@ -9,5 +10,6 @@ public partial class PaletteDemo : UserControl public PaletteDemo() { InitializeComponent(); + this.DataContext = new PaletteDemoViewModel(); } } \ No newline at end of file diff --git a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml index 6a113d4..e3c7231 100644 --- a/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml +++ b/demo/Semi.Avalonia.Demo/Themes/ToggleButton.axaml @@ -27,7 +27,6 @@ - diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs index a4f7904..515c832 100644 --- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs +++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs @@ -1,4 +1,8 @@ +using System; +using System.Collections.ObjectModel; using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Media; using CommunityToolkit.Mvvm.ComponentModel; namespace Semi.Avalonia.Demo.ViewModels; @@ -6,12 +10,95 @@ namespace Semi.Avalonia.Demo.ViewModels; public class PaletteDemoViewModel: ObservableObject { private string[] _colors = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" }; + private ObservableCollection _series; + + public ObservableCollection Series + { + get => _series; + set => SetProperty(ref _series, value); + } + + public PaletteDemoViewModel() + { + Series = new ObservableCollection(); + var resouceDictionary = (ResourceDictionary)(AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"))); + foreach (var color in _colors) + { + ColorSeries s = new ColorSeries(); + s.Initialize(resouceDictionary, color); + Series.Add(s); + } + } } public class ColorSeries: ObservableObject { + private ObservableCollection? _colors; + + public ObservableCollection? Color + { + get => _colors; + set => SetProperty(ref _colors, value); + } + + private string? _seriesName; + + public string? SeriesName + { + get => _seriesName; + set => SetProperty(ref _seriesName, value); + } + internal void Initialize(IResourceDictionary resourceDictionary, string color) { + SeriesName = color; + Color = new ObservableCollection(); + for (int i = 0; i < 10; i++) + { + var key = "Semi" + color + i; + if (resourceDictionary.TryGetValue(key, out var value)) + { + if (value is SolidColorBrush brush) + { + string name = color + " " + i; + var item = new ColorItemViewModel(name, brush, key); + Color.Add(item); + } + } + } + } +} + +public class ColorItemViewModel : ObservableObject +{ + + private IBrush _color; + public IBrush Color + { + get => _color; + set => SetProperty(ref _color, value); + } + + private string _name; + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + + private string _resourceKey; + + public string ResourceKey + { + get => _resourceKey; + set => SetProperty(ref _resourceKey, value); + } + + public ColorItemViewModel(string name, IBrush color, string resourceKey) + { + Name = name; + Color = color; + ResourceKey = resourceKey; } } \ No newline at end of file