[ImageResizer]Fix combo boxes bindings to hide height for percent(#31332)

* [ImageResizer] Fix combo boxes bindings

* Fix exception
This commit is contained in:
Stefan Markovic
2024-02-08 15:06:27 +01:00
committed by GitHub
parent d0793b3b7e
commit 04f5147cde
4 changed files with 31 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
<v:AutoDoubleConverter x:Key="AutoDoubleConverter" /> <v:AutoDoubleConverter x:Key="AutoDoubleConverter" />
<v:BoolValueConverter x:Key="BoolValueConverter" /> <v:BoolValueConverter x:Key="BoolValueConverter" />
<v:VisibilityBoolConverter x:Key="VisibilityBoolConverter" /> <v:VisibilityBoolConverter x:Key="VisibilityBoolConverter" />
<v:EnumToIntConverter x:Key="EnumToIntConverter" />
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

View 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);
}
}

View File

@@ -16,6 +16,11 @@ namespace ImageResizer.Views
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{ {
var type = value?.GetType(); var type = value?.GetType();
if (!type.IsEnum)
{
return value;
}
var builder = new StringBuilder(); var builder = new StringBuilder();
builder builder

View File

@@ -179,9 +179,9 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
AutomationProperties.Name="{x:Static p:Resources.Resize_Type}" AutomationProperties.Name="{x:Static p:Resources.Resize_Type}"
ItemsSource="{Binding ResizeFitValues, Mode=OneWay}" ItemsSource="{Binding ResizeFitValues, Mode=OneWay}"
SelectedIndex="0"> SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Fit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate DataType="sys:Enum"> <DataTemplate DataType="{x:Type m:ResizeFit}">
<TextBlock <TextBlock
Margin="4,0,0,0" Margin="4,0,0,0"
FontSize="14" FontSize="14"
@@ -206,9 +206,9 @@
Grid.Column="4" Grid.Column="4"
AutomationProperties.Name="{x:Static p:Resources.Unit}" AutomationProperties.Name="{x:Static p:Resources.Unit}"
ItemsSource="{Binding ResizeUnitValues, Mode=OneWay}" ItemsSource="{Binding ResizeUnitValues, Mode=OneWay}"
SelectedIndex="0"> SelectedIndex="{Binding ElementName=SizeComboBox, Path=SelectedValue.Unit, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate DataType="sys:Enum"> <DataTemplate DataType="{x:Type m:ResizeUnit}">
<TextBlock <TextBlock
Margin="4,0,0,0" Margin="4,0,0,0"
FontSize="14" FontSize="14"