40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
|
|
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
|
|
// All Rights Reserved.
|
|
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using Wpf.Ui.Appearance;
|
|
|
|
namespace DownloadManager.Helpers;
|
|
internal class EnumToBooleanConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter is not String enumString)
|
|
{
|
|
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
|
|
}
|
|
|
|
if (!Enum.IsDefined(typeof(ApplicationTheme), value))
|
|
{
|
|
throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum");
|
|
}
|
|
|
|
var enumValue = Enum.Parse(typeof(ApplicationTheme), enumString);
|
|
|
|
return enumValue.Equals(value);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (parameter is not String enumString)
|
|
{
|
|
throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
|
|
}
|
|
|
|
return Enum.Parse(typeof(ApplicationTheme), enumString);
|
|
}
|
|
}
|