mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
|
// 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.Text;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
using ImageResizer.Properties;
|
|||
|
|
|
|||
|
|
namespace ImageResizer.Views
|
|||
|
|
{
|
|||
|
|
[ValueConversion(typeof(Enum), typeof(string))]
|
|||
|
|
public class EnumValueConverter : IValueConverter
|
|||
|
|
{
|
|||
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
var type = value.GetType();
|
|||
|
|
var builder = new StringBuilder();
|
|||
|
|
|
|||
|
|
builder
|
|||
|
|
.Append(type.Name)
|
|||
|
|
.Append("_")
|
|||
|
|
.Append(Enum.GetName(type, value));
|
|||
|
|
|
|||
|
|
var toLower = false;
|
|||
|
|
if ((string)parameter == "ToLower")
|
|||
|
|
{
|
|||
|
|
toLower = true;
|
|||
|
|
}
|
|||
|
|
else if (parameter != null)
|
|||
|
|
{
|
|||
|
|
builder
|
|||
|
|
.Append("_")
|
|||
|
|
.Append(parameter);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var targetValue = Resources.ResourceManager.GetString(builder.ToString());
|
|||
|
|
|
|||
|
|
if (toLower)
|
|||
|
|
{
|
|||
|
|
targetValue = targetValue.ToLower();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return targetValue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
=> value;
|
|||
|
|
}
|
|||
|
|
}
|