committed by
GitHub
12 changed files with 361 additions and 11 deletions
@ -0,0 +1,142 @@ |
|||||
|
<UserControl x:Class="ControlCatalog.Pages.PlatformSettingsPage" |
||||
|
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" |
||||
|
xmlns:viewModels="using:ControlCatalog.ViewModels" |
||||
|
d:DesignHeight="800" |
||||
|
d:DesignWidth="600" |
||||
|
mc:Ignorable="d" |
||||
|
x:DataType="viewModels:PlatformSettingsViewModel"> |
||||
|
|
||||
|
<ScrollViewer> |
||||
|
<StackPanel Spacing="20" Margin="20"> |
||||
|
|
||||
|
<TextBlock Text="Platform Settings Information" |
||||
|
FontSize="20" |
||||
|
FontWeight="Bold" /> |
||||
|
|
||||
|
<TextBlock Text="This page displays IPlatformSettings values which may change at runtime based on system settings." |
||||
|
TextWrapping="Wrap" |
||||
|
Opacity="0.7" /> |
||||
|
|
||||
|
<GroupBox Header="System Color Values"> |
||||
|
<StackPanel Spacing="15"> |
||||
|
<Grid ColumnDefinitions="180,*" RowDefinitions="Auto,Auto,Auto"> |
||||
|
<TextBlock Grid.Column="0" Grid.Row="0" Text="Theme Variant:" VerticalAlignment="Center" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ThemeVariant}" FontWeight="Bold" VerticalAlignment="Center" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="1" Text="Contrast Preference:" VerticalAlignment="Center" Margin="0,10,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding ContrastPreference}" FontWeight="Bold" VerticalAlignment="Center" Margin="0,10,0,0" /> |
||||
|
</Grid> |
||||
|
|
||||
|
<StackPanel Spacing="10"> |
||||
|
<Grid ColumnDefinitions="180,120,*"> |
||||
|
<TextBlock Grid.Column="0" Text="Accent Color 1:" VerticalAlignment="Center" /> |
||||
|
<Border Grid.Column="1" |
||||
|
Width="100" |
||||
|
Height="40" |
||||
|
BorderBrush="Black" |
||||
|
BorderThickness="1" |
||||
|
CornerRadius="4" |
||||
|
HorizontalAlignment="Left"> |
||||
|
<Border.Background> |
||||
|
<SolidColorBrush Color="{Binding AccentColor1}" /> |
||||
|
</Border.Background> |
||||
|
</Border> |
||||
|
<TextBlock Grid.Column="2" |
||||
|
Text="{Binding AccentColor1}" |
||||
|
VerticalAlignment="Center" |
||||
|
Margin="10,0,0,0" /> |
||||
|
</Grid> |
||||
|
|
||||
|
<Grid ColumnDefinitions="180,120,*"> |
||||
|
<TextBlock Grid.Column="0" Text="Accent Color 2:" VerticalAlignment="Center" /> |
||||
|
<Border Grid.Column="1" |
||||
|
Width="100" |
||||
|
Height="40" |
||||
|
BorderBrush="Black" |
||||
|
BorderThickness="1" |
||||
|
CornerRadius="4" |
||||
|
HorizontalAlignment="Left"> |
||||
|
<Border.Background> |
||||
|
<SolidColorBrush Color="{Binding AccentColor2}" /> |
||||
|
</Border.Background> |
||||
|
</Border> |
||||
|
<TextBlock Grid.Column="2" |
||||
|
Text="{Binding AccentColor2}" |
||||
|
VerticalAlignment="Center" |
||||
|
Margin="10,0,0,0" /> |
||||
|
</Grid> |
||||
|
|
||||
|
<Grid ColumnDefinitions="180,120,*"> |
||||
|
<TextBlock Grid.Column="0" Text="Accent Color 3:" VerticalAlignment="Center" /> |
||||
|
<Border Grid.Column="1" |
||||
|
Width="100" |
||||
|
Height="40" |
||||
|
BorderBrush="Black" |
||||
|
BorderThickness="1" |
||||
|
CornerRadius="4" |
||||
|
HorizontalAlignment="Left"> |
||||
|
<Border.Background> |
||||
|
<SolidColorBrush Color="{Binding AccentColor3}" /> |
||||
|
</Border.Background> |
||||
|
</Border> |
||||
|
<TextBlock Grid.Column="2" |
||||
|
Text="{Binding AccentColor3}" |
||||
|
VerticalAlignment="Center" |
||||
|
Margin="10,0,0,0" /> |
||||
|
</Grid> |
||||
|
</StackPanel> |
||||
|
</StackPanel> |
||||
|
</GroupBox> |
||||
|
|
||||
|
<GroupBox Header="Language Settings"> |
||||
|
<StackPanel Spacing="10"> |
||||
|
<TextBlock Text="This reflects the preferred application language as specified in OS settings." |
||||
|
TextWrapping="Wrap" |
||||
|
Opacity="0.7" |
||||
|
FontSize="12" /> |
||||
|
<Grid ColumnDefinitions="180,*"> |
||||
|
<TextBlock Grid.Column="0" Text="Preferred Language:" VerticalAlignment="Center" /> |
||||
|
<TextBlock Grid.Column="1" Text="{Binding PreferredLanguage}" FontWeight="Bold" VerticalAlignment="Center" /> |
||||
|
</Grid> |
||||
|
</StackPanel> |
||||
|
</GroupBox> |
||||
|
|
||||
|
<GroupBox Header="Other Platform Settings"> |
||||
|
<StackPanel Spacing="10"> |
||||
|
<TextBlock Text="These settings are less commonly changed and are platform-specific." |
||||
|
TextWrapping="Wrap" |
||||
|
Opacity="0.7" |
||||
|
FontSize="12" /> |
||||
|
|
||||
|
<Grid ColumnDefinitions="180,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"> |
||||
|
<TextBlock Grid.Column="0" Grid.Row="0" Text="Hold Wait Duration:" VerticalAlignment="Center" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding HoldWaitDuration}" VerticalAlignment="Center" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="1" Text="Tap Size (Touch):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding TapSizeTouch}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="2" Text="Tap Size (Mouse):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding TapSizeMouse}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="3" Text="Double-Tap Size (Touch):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding DoubleTapSizeTouch}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="4" Text="Double-Tap Size (Mouse):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="4" Text="{Binding DoubleTapSizeMouse}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="5" Text="Double-Tap Time (Touch):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="5" Text="{Binding DoubleTapTimeTouch}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
|
||||
|
<TextBlock Grid.Column="0" Grid.Row="6" Text="Double-Tap Time (Mouse):" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
<TextBlock Grid.Column="1" Grid.Row="6" Text="{Binding DoubleTapTimeMouse}" VerticalAlignment="Center" Margin="0,5,0,0" /> |
||||
|
</Grid> |
||||
|
</StackPanel> |
||||
|
</GroupBox> |
||||
|
|
||||
|
</StackPanel> |
||||
|
</ScrollViewer> |
||||
|
</UserControl> |
||||
|
|
||||
@ -0,0 +1,15 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using ControlCatalog.ViewModels; |
||||
|
|
||||
|
namespace ControlCatalog.Pages |
||||
|
{ |
||||
|
public partial class PlatformSettingsPage : UserControl |
||||
|
{ |
||||
|
public PlatformSettingsPage() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
DataContext = new PlatformSettingsViewModel(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,77 @@ |
|||||
|
using System; |
||||
|
using Avalonia; |
||||
|
using Avalonia.Input; |
||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Platform; |
||||
|
using MiniMvvm; |
||||
|
|
||||
|
namespace ControlCatalog.ViewModels; |
||||
|
|
||||
|
public class PlatformSettingsViewModel : ViewModelBase |
||||
|
{ |
||||
|
private readonly IPlatformSettings? _platformSettings; |
||||
|
private PlatformColorValues? _colorValues; |
||||
|
private string? _preferredLanguage; |
||||
|
|
||||
|
public PlatformSettingsViewModel() |
||||
|
{ |
||||
|
_platformSettings = AvaloniaLocator.Current.GetService<IPlatformSettings>(); |
||||
|
|
||||
|
if (_platformSettings != null) |
||||
|
{ |
||||
|
_colorValues = _platformSettings.GetColorValues(); |
||||
|
_preferredLanguage = _platformSettings.PreferredApplicationLanguage; |
||||
|
|
||||
|
_platformSettings.ColorValuesChanged += OnColorValuesChanged; |
||||
|
_platformSettings.PreferredApplicationLanguageChanged += OnPreferredLanguageChanged; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void OnColorValuesChanged(object? sender, PlatformColorValues e) |
||||
|
{ |
||||
|
_colorValues = e; |
||||
|
RaisePropertyChanged(nameof(ThemeVariant)); |
||||
|
RaisePropertyChanged(nameof(ContrastPreference)); |
||||
|
RaisePropertyChanged(nameof(AccentColor1)); |
||||
|
RaisePropertyChanged(nameof(AccentColor2)); |
||||
|
RaisePropertyChanged(nameof(AccentColor3)); |
||||
|
} |
||||
|
|
||||
|
private void OnPreferredLanguageChanged(object? sender, EventArgs e) |
||||
|
{ |
||||
|
if (_platformSettings != null) |
||||
|
{ |
||||
|
_preferredLanguage = _platformSettings.PreferredApplicationLanguage; |
||||
|
RaisePropertyChanged(nameof(PreferredLanguage)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public bool IsAvailable => _platformSettings != null; |
||||
|
|
||||
|
public string PreferredLanguage => _preferredLanguage ?? "Not available"; |
||||
|
|
||||
|
public string ThemeVariant => _colorValues?.ThemeVariant.ToString() ?? "Not available"; |
||||
|
|
||||
|
public string ContrastPreference => _colorValues?.ContrastPreference.ToString() ?? "Not available"; |
||||
|
|
||||
|
public Color AccentColor1 => _colorValues?.AccentColor1 ?? Colors.Gray; |
||||
|
|
||||
|
public Color AccentColor2 => _colorValues?.AccentColor2 ?? Colors.Gray; |
||||
|
|
||||
|
public Color AccentColor3 => _colorValues?.AccentColor3 ?? Colors.Gray; |
||||
|
|
||||
|
public string HoldWaitDuration => _platformSettings?.HoldWaitDuration.ToString() ?? "Not available"; |
||||
|
|
||||
|
public string TapSizeTouch => _platformSettings?.GetTapSize(PointerType.Touch).ToString() ?? "Not available"; |
||||
|
|
||||
|
public string TapSizeMouse => _platformSettings?.GetTapSize(PointerType.Mouse).ToString() ?? "Not available"; |
||||
|
|
||||
|
public string DoubleTapSizeTouch => _platformSettings?.GetDoubleTapSize(PointerType.Touch).ToString() ?? "Not available"; |
||||
|
|
||||
|
public string DoubleTapSizeMouse => _platformSettings?.GetDoubleTapSize(PointerType.Mouse).ToString() ?? "Not available"; |
||||
|
|
||||
|
public string DoubleTapTimeTouch => _platformSettings?.GetDoubleTapTime(PointerType.Touch).ToString() ?? "Not available"; |
||||
|
|
||||
|
public string DoubleTapTimeMouse => _platformSettings?.GetDoubleTapTime(PointerType.Mouse).ToString() ?? "Not available"; |
||||
|
} |
||||
|
|
||||
Loading…
Reference in new issue