2021-07-26 19:00:53 +02:00
|
|
|
|
// 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;
|
2025-01-21 11:55:02 +00:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-26 19:00:53 +02:00
|
|
|
|
using System.Globalization;
|
2025-01-21 11:55:02 +00:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
2022-04-19 22:00:28 +02:00
|
|
|
|
using Microsoft.UI.Xaml.Data;
|
2021-07-26 19:00:53 +02:00
|
|
|
|
|
2025-01-21 11:55:02 +00:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Converters;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed partial class ImageResizerFitToStringConverter : IValueConverter
|
2021-07-26 19:00:53 +02:00
|
|
|
|
{
|
2025-01-21 11:55:02 +00:00
|
|
|
|
// Maps each ResizeFit to its localized string.
|
|
|
|
|
|
private static readonly Dictionary<ResizeFit, string> FitToText = new()
|
2021-07-26 19:00:53 +02:00
|
|
|
|
{
|
2025-01-21 11:55:02 +00:00
|
|
|
|
{ ResizeFit.Fill, Helpers.ResourceLoaderInstance.ResourceLoader.GetString("ImageResizer_Fit_Fill_ThirdPersonSingular") },
|
|
|
|
|
|
{ ResizeFit.Fit, Helpers.ResourceLoaderInstance.ResourceLoader.GetString("ImageResizer_Fit_Fit_ThirdPersonSingular") },
|
|
|
|
|
|
{ ResizeFit.Stretch, Helpers.ResourceLoaderInstance.ResourceLoader.GetString("ImageResizer_Fit_Stretch_ThirdPersonSingular") },
|
|
|
|
|
|
};
|
2021-07-26 19:00:53 +02:00
|
|
|
|
|
2025-01-21 11:55:02 +00:00
|
|
|
|
public object Convert(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value is ResizeFit fit && FitToText.TryGetValue(fit, out string fitText))
|
2021-07-26 19:00:53 +02:00
|
|
|
|
{
|
2025-01-21 11:55:02 +00:00
|
|
|
|
return parameter is string lowerParam && lowerParam == "ToLower" ?
|
|
|
|
|
|
fitText.ToLower(CultureInfo.CurrentCulture) :
|
|
|
|
|
|
fitText;
|
2021-07-26 19:00:53 +02:00
|
|
|
|
}
|
2025-01-21 11:55:02 +00:00
|
|
|
|
|
|
|
|
|
|
return DependencyProperty.UnsetValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
|
|
|
|
{
|
|
|
|
|
|
return value;
|
2021-07-26 19:00:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|