Browse Source

Use enum items array instead of strings in control catalog settings

pull/7141/head
Max Katz 5 years ago
parent
commit
ec23173a0a
  1. 21
      samples/ControlCatalog/MainView.xaml
  2. 32
      samples/ControlCatalog/MainView.xaml.cs
  3. 14
      samples/ControlCatalog/Models/CatalogTheme.cs

21
samples/ControlCatalog/MainView.xaml

@ -2,7 +2,8 @@
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:ControlSamples;assembly=ControlSamples" xmlns:controls="clr-namespace:ControlSamples;assembly=ControlSamples"
xmlns:pages="clr-namespace:ControlCatalog.Pages"> xmlns:pages="clr-namespace:ControlCatalog.Pages"
xmlns:models="clr-namespace:ControlCatalog.Models">
<Grid> <Grid>
<Grid.Styles> <Grid.Styles>
<Style Selector="TextBlock.h2"> <Style Selector="TextBlock.h2">
@ -156,17 +157,21 @@
<ComboBox x:Name="Decorations" <ComboBox x:Name="Decorations"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
SelectedIndex="0"> SelectedIndex="0">
<ComboBoxItem>No Decorations</ComboBoxItem> <ComboBox.Items>
<ComboBoxItem>Border Only</ComboBoxItem> <SystemDecorations>None</SystemDecorations>
<ComboBoxItem>Full Decorations</ComboBoxItem> <SystemDecorations>BorderOnly</SystemDecorations>
<SystemDecorations>Full</SystemDecorations>
</ComboBox.Items>
</ComboBox> </ComboBox>
<ComboBox x:Name="Themes" <ComboBox x:Name="Themes"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
SelectedIndex="0"> SelectedIndex="0">
<ComboBoxItem>Fluent - Light</ComboBoxItem> <ComboBox.Items>
<ComboBoxItem>Fluent - Dark</ComboBoxItem> <models:CatalogTheme>FluentLight</models:CatalogTheme>
<ComboBoxItem>Simple - Light</ComboBoxItem> <models:CatalogTheme>FluentDark</models:CatalogTheme>
<ComboBoxItem>Simple - Dark</ComboBoxItem> <models:CatalogTheme>DefaultLight</models:CatalogTheme>
<models:CatalogTheme>DefaultDark</models:CatalogTheme>
</ComboBox.Items>
</ComboBox> </ComboBox>
<ComboBox x:Name="TransparencyLevels" <ComboBox x:Name="TransparencyLevels"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"

32
samples/ControlCatalog/MainView.xaml.cs

@ -10,6 +10,7 @@ using Avalonia.Media;
using Avalonia.Media.Immutable; using Avalonia.Media.Immutable;
using Avalonia.Platform; using Avalonia.Platform;
using ControlCatalog.Pages; using ControlCatalog.Pages;
using ControlCatalog.Models;
namespace ControlCatalog namespace ControlCatalog
{ {
@ -40,28 +41,27 @@ namespace ControlCatalog
var themes = this.Find<ComboBox>("Themes"); var themes = this.Find<ComboBox>("Themes");
themes.SelectionChanged += (sender, e) => themes.SelectionChanged += (sender, e) =>
{ {
switch (themes.SelectedIndex) if (themes.SelectedItem is CatalogTheme theme)
{ {
case 0: Application.Current.Styles[0] = theme switch
Application.Current.Styles[0] = App.FluentLight; {
break; CatalogTheme.FluentLight => App.FluentLight,
case 1: CatalogTheme.FluentDark => App.FluentDark,
Application.Current.Styles[0] = App.FluentDark; CatalogTheme.DefaultLight => App.DefaultLight,
break; CatalogTheme.DefaultDark => App.DefaultDark,
case 2: _ => Application.Current.Styles[0]
Application.Current.Styles[0] = App.DefaultLight; };
break;
case 3:
Application.Current.Styles[0] = App.DefaultDark;
break;
} }
}; };
var decorations = this.Find<ComboBox>("Decorations"); var decorations = this.Find<ComboBox>("Decorations");
decorations.SelectionChanged += (sender, e) => decorations.SelectionChanged += (sender, e) =>
{ {
if (VisualRoot is Window window) if (VisualRoot is Window window
window.SystemDecorations = (SystemDecorations)decorations.SelectedIndex; && decorations.SelectedItem is SystemDecorations systemDecorations)
{
window.SystemDecorations = systemDecorations;
}
}; };
var transparencyLevels = this.Find<ComboBox>("TransparencyLevels"); var transparencyLevels = this.Find<ComboBox>("TransparencyLevels");

14
samples/ControlCatalog/Models/CatalogTheme.cs

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ControlCatalog.Models
{
public enum CatalogTheme
{
FluentLight,
FluentDark,
DefaultLight,
DefaultDark
}
}
Loading…
Cancel
Save