mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-30 22:15:11 +00:00
[ImageResizer]Fix combo boxes bindings to hide height for percent(#31332)
* [ImageResizer] Fix combo boxes bindings * Fix exception
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<v:AutoDoubleConverter x:Key="AutoDoubleConverter" />
|
||||
<v:BoolValueConverter x:Key="BoolValueConverter" />
|
||||
<v:VisibilityBoolConverter x:Key="VisibilityBoolConverter" />
|
||||
<v:EnumToIntConverter x:Key="EnumToIntConverter" />
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
21
src/modules/imageresizer/ui/Views/EnumToIntConverter.cs
Normal file
21
src/modules/imageresizer/ui/Views/EnumToIntConverter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Brice Lambson
|
||||
// The Brice Lambson licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information. Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ImageResizer.Views
|
||||
{
|
||||
[ValueConversion(typeof(Enum), typeof(int))]
|
||||
internal class EnumToIntConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> (int)value;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
=> targetType.GetEnumValues().GetValue((int)value);
|
||||
}
|
||||
}
|
@@ -16,6 +16,11 @@ namespace ImageResizer.Views
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var type = value?.GetType();
|
||||
if (!type.IsEnum)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder();
|
||||
|
||||
builder
|
||||
|
@@ -179,9 +179,9 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
AutomationProperties.Name="{x:Static p:Resources.Resize_Type}"
|
||||
ItemsSource="{Binding ResizeFitValues, Mode=OneWay}"
|
||||
SelectedIndex="0">
|
||||
SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Fit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="sys:Enum">
|
||||
<DataTemplate DataType="{x:Type m:ResizeFit}">
|
||||
<TextBlock
|
||||
Margin="4,0,0,0"
|
||||
FontSize="14"
|
||||
@@ -206,9 +206,9 @@
|
||||
Grid.Column="4"
|
||||
AutomationProperties.Name="{x:Static p:Resources.Unit}"
|
||||
ItemsSource="{Binding ResizeUnitValues, Mode=OneWay}"
|
||||
SelectedIndex="0">
|
||||
SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Unit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate DataType="sys:Enum">
|
||||
<DataTemplate DataType="{x:Type m:ResizeUnit}">
|
||||
<TextBlock
|
||||
Margin="4,0,0,0"
|
||||
FontSize="14"
|
||||
|
Reference in New Issue
Block a user