[Image Resizer] Added AutomationProperties.HelpText to dimensions combo-box
This commit is contained in:
Родитель
2c069ce708
Коммит
6164aafb99
|
@ -14,6 +14,7 @@
|
|||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<v:SizeTypeToVisibilityConverter x:Key="SizeTypeToVisibilityConverter" />
|
||||
<v:SizeTypeToHelpTextConverter x:Key="SizeTypeToHelpTextConverter" />
|
||||
<v:EnumValueConverter x:Key="EnumValueConverter" />
|
||||
<v:AutoDoubleConverter x:Key="AutoDoubleConverter" />
|
||||
<v:BoolValueConverter x:Key="BoolValueConverter" />
|
||||
|
|
|
@ -254,6 +254,7 @@ namespace ImageResizer.Properties
|
|||
{
|
||||
_selectedSizeIndex = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(SelectedSize));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,19 @@
|
|||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
VerticalContentAlignment="Stretch"
|
||||
AutomationProperties.HelpText="{Binding Settings.SelectedSize, Converter={StaticResource SizeTypeToHelpTextConverter}}"
|
||||
AutomationProperties.Name="{x:Static p:Resources.Image_Sizes}"
|
||||
ItemsSource="{Binding Settings.AllSizes}"
|
||||
SelectedIndex="{Binding Settings.SelectedSizeIndex}">
|
||||
<ComboBox.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource {x:Type ComboBoxItem}}" TargetType="ComboBoxItem">
|
||||
<Setter Property="AutomationProperties.Name" Value="{Binding Name}" />
|
||||
<Setter Property="AutomationProperties.HelpText" Value="{Binding ., Converter={StaticResource SizeTypeToHelpTextConverter}}" />
|
||||
</Style>
|
||||
</ComboBox.ItemContainerStyle>
|
||||
<ComboBox.Resources>
|
||||
<DataTemplate DataType="{x:Type m:ResizeSize}">
|
||||
<Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
|
@ -55,7 +62,7 @@
|
|||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type m:CustomSize}">
|
||||
<Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<TextBlock FontWeight="SemiBold" Text="{Binding Name}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
using ImageResizer.Models;
|
||||
|
||||
namespace ImageResizer.Views;
|
||||
|
||||
[ValueConversion(typeof(ResizeSize), typeof(string))]
|
||||
public sealed partial class SizeTypeToHelpTextConverter : IValueConverter
|
||||
{
|
||||
private const char MultiplicationSign = '\u00D7';
|
||||
|
||||
private readonly EnumValueConverter _enumConverter = new();
|
||||
private readonly AutoDoubleConverter _autoDoubleConverter = new();
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not ResizeSize size)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
string EnumToString(Enum value, string parameter = null) =>
|
||||
_enumConverter.Convert(value, typeof(string), parameter, culture) as string;
|
||||
|
||||
string DoubleToString(double value) =>
|
||||
_autoDoubleConverter.Convert(value, typeof(string), null, culture) as string;
|
||||
|
||||
var fit = EnumToString(size.Fit, "ThirdPersonSingular");
|
||||
var width = DoubleToString(size.Width);
|
||||
var unit = EnumToString(size.Unit);
|
||||
|
||||
return size.ShowHeight ?
|
||||
$"{fit} {width} {MultiplicationSign} {DoubleToString(size.Height)} {unit}" :
|
||||
$"{fit} {width} {unit}";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> throw new NotImplementedException();
|
||||
}
|
Загрузка…
Ссылка в новой задаче