Browse Source

Add titlecase display for language options

pull/238/head
Ionite 1 year ago
parent
commit
63c166f7cc
No known key found for this signature in database
  1. 28
      StabilityMatrix.Avalonia/Converters/CultureInfoDisplayConverter.cs
  2. 7
      StabilityMatrix.Avalonia/Views/SettingsPage.axaml

28
StabilityMatrix.Avalonia/Converters/CultureInfoDisplayConverter.cs

@ -0,0 +1,28 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
namespace StabilityMatrix.Avalonia.Converters;
public class CultureInfoDisplayConverter : IValueConverter
{
/// <inheritdoc />
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not CultureInfo cultureInfo)
return null;
return cultureInfo.TextInfo.ToTitleCase(cultureInfo.NativeName);
}
/// <inheritdoc />
public object ConvertBack(
object? value,
Type targetType,
object? parameter,
CultureInfo culture
)
{
throw new NotImplementedException();
}
}

7
StabilityMatrix.Avalonia/Views/SettingsPage.axaml

@ -10,6 +10,7 @@
xmlns:ui="using:FluentAvalonia.UI.Controls"
xmlns:vm="clr-namespace:StabilityMatrix.Avalonia.ViewModels"
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
xmlns:converters="clr-namespace:StabilityMatrix.Avalonia.Converters"
d:DataContext="{x:Static mocks:DesignData.SettingsViewModel}"
d:DesignHeight="700"
d:DesignWidth="800"
@ -17,6 +18,10 @@
x:DataType="vm:SettingsViewModel"
mc:Ignorable="d">
<controls:UserControlBase.Resources>
<converters:CultureInfoDisplayConverter x:Key="CultureInfoDisplayConverter" />
</controls:UserControlBase.Resources>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Margin="8,16" Spacing="8">
<!-- Theme -->
@ -46,7 +51,7 @@
<ComboBox
MinWidth="100"
ItemsSource="{Binding AvailableLanguages}"
DisplayMemberBinding="{Binding NativeName}"
DisplayMemberBinding="{Binding Converter={StaticResource CultureInfoDisplayConverter}}"
SelectedItem="{Binding SelectedLanguage}" />
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>

Loading…
Cancel
Save