Add project files.
This commit is contained in:
39
Helpers/EnumToBooleanConverter.cs
Normal file
39
Helpers/EnumToBooleanConverter.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user