mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Image Resizer] Added AutomationProperties.HelpText to dimensions combo-box (#37122)
Co-authored-by: Stefan Markovic <stefan@janeasystems.com>
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
|
||||||
<v:SizeTypeToVisibilityConverter x:Key="SizeTypeToVisibilityConverter" />
|
<v:SizeTypeToVisibilityConverter x:Key="SizeTypeToVisibilityConverter" />
|
||||||
|
<v:SizeTypeToHelpTextConverter x:Key="SizeTypeToHelpTextConverter" />
|
||||||
<v:EnumValueConverter x:Key="EnumValueConverter" />
|
<v:EnumValueConverter x:Key="EnumValueConverter" />
|
||||||
<v:AutoDoubleConverter x:Key="AutoDoubleConverter" />
|
<v:AutoDoubleConverter x:Key="AutoDoubleConverter" />
|
||||||
<v:BoolValueConverter x:Key="BoolValueConverter" />
|
<v:BoolValueConverter x:Key="BoolValueConverter" />
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ namespace ImageResizer.Properties
|
|||||||
{
|
{
|
||||||
_selectedSizeIndex = value;
|
_selectedSizeIndex = value;
|
||||||
NotifyPropertyChanged();
|
NotifyPropertyChanged();
|
||||||
|
NotifyPropertyChanged(nameof(SelectedSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,19 @@
|
|||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
VerticalContentAlignment="Stretch"
|
VerticalContentAlignment="Stretch"
|
||||||
|
AutomationProperties.HelpText="{Binding Settings.SelectedSize, Converter={StaticResource SizeTypeToHelpTextConverter}}"
|
||||||
AutomationProperties.Name="{x:Static p:Resources.Image_Sizes}"
|
AutomationProperties.Name="{x:Static p:Resources.Image_Sizes}"
|
||||||
ItemsSource="{Binding Settings.AllSizes}"
|
ItemsSource="{Binding Settings.AllSizes}"
|
||||||
SelectedIndex="{Binding Settings.SelectedSizeIndex}">
|
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>
|
<ComboBox.Resources>
|
||||||
<DataTemplate DataType="{x:Type m:ResizeSize}">
|
<DataTemplate DataType="{x:Type m:ResizeSize}">
|
||||||
<Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
|
<Grid VerticalAlignment="Center">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
@@ -55,7 +62,7 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate DataType="{x:Type m:CustomSize}">
|
<DataTemplate DataType="{x:Type m:CustomSize}">
|
||||||
<Grid VerticalAlignment="Center" AutomationProperties.Name="{Binding Name}">
|
<Grid VerticalAlignment="Center">
|
||||||
<TextBlock FontWeight="SemiBold" Text="{Binding Name}" />
|
<TextBlock FontWeight="SemiBold" Text="{Binding Name}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user