diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-02-28 00:45:53 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-02-28 00:45:53 +0300 |
commit | 4a4800024bb834be12dab8ddc749aa8f51368dd6 (patch) | |
tree | 3ebae12291e619d760d3e4a583e2d56845b72cd6 /Xamarin.PropertyEditing.Windows.Standalone | |
parent | 4899f6947f6d42251ac276aa016b41db5d57d48b (diff) |
[Tests] Add font/locale selection to standalone
Diffstat (limited to 'Xamarin.PropertyEditing.Windows.Standalone')
-rw-r--r-- | Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml | 32 | ||||
-rw-r--r-- | Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs | 66 |
2 files changed, 75 insertions, 23 deletions
diff --git a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml index 1019440..b7b0645 100644 --- a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml +++ b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml @@ -14,22 +14,40 @@ </Grid.ColumnDefinitions> <Grid.RowDefinitions> - <RowDefinition Height="22" /> + <RowDefinition Height="Auto" /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> - <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal"> - <RadioButton GroupName="theme" Padding="5, 0, 20, 0" Click="Theme_Click" IsChecked="True">Dark Theme</RadioButton> - <RadioButton GroupName="theme" Padding="5, 0, 20, 0" Click="Theme_Click">Light Theme</RadioButton> - <RadioButton GroupName="theme" Padding="5, 0, 20, 0" Click="Theme_Click">No Theme</RadioButton> - </StackPanel> + <Grid Grid.Row="0"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Grid.ColumnDefinitions> + <ColumnDefinition /> + <ColumnDefinition /> + <ColumnDefinition /> + </Grid.ColumnDefinitions> + <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center">Theme:</TextBlock> + <ComboBox Name="theme" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" SelectionChanged="Theme_SelectionChanged"> + <ComboBoxItem IsSelected="True">Dark</ComboBoxItem> + <ComboBoxItem>Light</ComboBoxItem> + </ComboBox> + <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">Font:</TextBlock> + <ComboBox Name="fonts" Grid.Row="1" Grid.Column="1" SelectionChanged="Fonts_SelectionChanged" /> + <TextBox Name="fontSize" Grid.Row="1" Grid.Column="2" TextChanged="FontSize_TextChanged" /> + + <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center">Locale:</TextBlock> + <ComboBox Name="locale" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" SelectionChanged="Locale_SelectionChanged" /> + </Grid> <local:MockedSampleControlButton Grid.Row="1" Grid.Column="0" Click="Button_Click">Mocked Sample 1</local:MockedSampleControlButton> <local:MockedSampleControlButton Grid.Row="2" Grid.Column="0" Click="Button_Click">Mocked Sample 2</local:MockedSampleControlButton> <local:MockedWpfButton Grid.Row="3" Grid.Column="0" Click="Button_Click">Mocked WPF button</local:MockedWpfButton> <Button Grid.Row="4" Grid.Column="0" Click="Button_Click">Actual WPF button</Button> - <xamarinprops:PropertyEditorPanel Name="panel" Grid.Row="1" Grid.RowSpan="4" Grid.Column="1" ArrangeMode="Category" /> + <xamarinprops:PropertyEditorPanel Name="panel" Grid.Row="0" Grid.RowSpan="5" Grid.Column="1" ArrangeMode="Category" /> </Grid> </Window>
\ No newline at end of file diff --git a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs index 93ddf21..246c70d 100644 --- a/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs +++ b/Xamarin.PropertyEditing.Windows.Standalone/MainWindow.xaml.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Windows; using System.Windows.Controls; +using System.Windows.Media; using Xamarin.PropertyEditing.Drawing; using Xamarin.PropertyEditing.Tests; @@ -15,6 +17,15 @@ namespace Xamarin.PropertyEditing.Windows.Standalone public MainWindow () { InitializeComponent (); + + this.fonts.ItemsSource = Fonts.SystemFontFamilies; + this.fonts.SelectedItem = FontFamily; + + this.fontSize.Text = this.fontSizeConverter.ConvertToString (FontSize); + + this.locale.ItemsSource = CultureInfo.GetCultures (CultureTypes.AllCultures); + this.locale.SelectedItem = CultureInfo.CurrentUICulture; + var resources = new MockResourceProvider(); this.panel.TargetPlatform = new TargetPlatform (new MockEditorProvider (resources), resources, new MockBindingProvider()) { SupportsCustomExpressions = true, @@ -42,6 +53,8 @@ namespace Xamarin.PropertyEditing.Windows.Standalone Source = new Uri ("pack://application:,,,/Xamarin.PropertyEditing.Windows;component/Themes/VS.Light.xaml") }; + private readonly FontSizeConverter fontSizeConverter = new FontSizeConverter(); + private async void Button_Click (object sender, RoutedEventArgs e) { object inspectedObject; @@ -63,23 +76,44 @@ namespace Xamarin.PropertyEditing.Windows.Standalone this.panel.SelectedItems.Add (inspectedObject); } - private void Theme_Click (object sender, RoutedEventArgs e) + private void Fonts_SelectionChanged (object sender, SelectionChangedEventArgs e) { - if (e.Source is RadioButton rb) { - switch (rb.Content.ToString ()) { - case "Dark Theme": - Application.Current.Resources.MergedDictionaries.Remove (LightTheme); - Application.Current.Resources.MergedDictionaries.Add (DarkTheme); - break; - case "Light Theme": - Application.Current.Resources.MergedDictionaries.Remove (DarkTheme); - Application.Current.Resources.MergedDictionaries.Add (LightTheme); - break; - default: - Application.Current.Resources.MergedDictionaries.Remove (LightTheme); - Application.Current.Resources.MergedDictionaries.Remove (DarkTheme); - break; - } + FontFamily = (FontFamily) this.fonts.SelectedItem; + } + + private void FontSize_TextChanged (object sender, TextChangedEventArgs e) + { + try { + object size = this.fontSizeConverter.ConvertFromString (this.fontSize.Text); + if (size == null) + return; + + FontSize = (double) size; + } catch (FormatException) { + } catch (NotSupportedException) { + } + } + + private void Locale_SelectionChanged (object sender, SelectionChangedEventArgs e) + { + CultureInfo.CurrentUICulture = (CultureInfo) this.locale.SelectedItem; + } + + private void Theme_SelectionChanged (object sender, SelectionChangedEventArgs e) + { + switch ((this.theme.SelectedItem as ComboBoxItem)?.Content?.ToString ()) { + case "Dark": + Application.Current.Resources.MergedDictionaries.Remove (LightTheme); + Application.Current.Resources.MergedDictionaries.Add (DarkTheme); + break; + case "Light": + Application.Current.Resources.MergedDictionaries.Remove (DarkTheme); + Application.Current.Resources.MergedDictionaries.Add (LightTheme); + break; + default: + Application.Current.Resources.MergedDictionaries.Remove (LightTheme); + Application.Current.Resources.MergedDictionaries.Remove (DarkTheme); + break; } } } |