mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-16 14:16:35 +08:00
feat: add more high contrast themes.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Styling;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Views;
|
||||
|
||||
@@ -11,6 +13,7 @@ public partial class MainView : UserControl
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new MainViewModel();
|
||||
}
|
||||
|
||||
private void ToggleButton_OnIsCheckedChanged(object sender, RoutedEventArgs e)
|
||||
@@ -38,4 +41,36 @@ public partial class MainView : UserControl
|
||||
var launcher = top.Launcher;
|
||||
await launcher.LaunchUriAsync(new Uri("https://docs.irihi.tech/semi"));
|
||||
}
|
||||
}
|
||||
|
||||
public partial class MainViewModel: ObservableObject
|
||||
{
|
||||
public ObservableCollection<ThemeItem> Themes { get; } = new()
|
||||
{
|
||||
new ThemeItem("Light", ThemeVariant.Light),
|
||||
new ThemeItem("Dark", ThemeVariant.Dark),
|
||||
new ThemeItem("Aquatic", SemiTheme.Aquatic),
|
||||
new ThemeItem("Desert", SemiTheme.Desert),
|
||||
new ThemeItem("Dust", SemiTheme.Dust),
|
||||
new ThemeItem("NightSky", SemiTheme.NightSky),
|
||||
};
|
||||
|
||||
[ObservableProperty] private ThemeItem? _selectedTheme;
|
||||
|
||||
partial void OnSelectedThemeChanged(ThemeItem? oldValue, ThemeItem? newValue)
|
||||
{
|
||||
if (newValue is null) return;
|
||||
var app = Application.Current;
|
||||
if (app is not null)
|
||||
{
|
||||
app.RequestedThemeVariant = newValue.Theme;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class ThemeItem(string name, ThemeVariant theme)
|
||||
{
|
||||
public string Name { get; set; } = name;
|
||||
public ThemeVariant Theme { get; set; } = theme;
|
||||
}
|
||||
Reference in New Issue
Block a user