mirror of
https://github.com/SabreTools/MPF.git
synced 2026-02-11 05:35:17 +00:00
45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using MPF.Core.Data;
|
|
using MPF.Core.UI.ComboBoxItems;
|
|
using SabreTools.RedumpLib.Data;
|
|
|
|
namespace MPF.UI.Core
|
|
{
|
|
internal class ElementConverter: IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value switch
|
|
{
|
|
DiscCategory discCategory => new Element<DiscCategory>(discCategory),
|
|
InternalProgram internalProgram => new Element<InternalProgram>(internalProgram),
|
|
MediaType mediaType => new Element<MediaType>(mediaType),
|
|
RedumpSystem redumpSystem => new RedumpSystemComboBoxItem(redumpSystem),
|
|
Region region => new Element<Region>(region),
|
|
|
|
// Null values are treated as a system value
|
|
_ => new RedumpSystemComboBoxItem((RedumpSystem?)null),
|
|
};
|
|
}
|
|
|
|
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
// If it's an IElement but ends up null
|
|
if (value is not IElement element)
|
|
return null;
|
|
|
|
return element switch
|
|
{
|
|
Element<DiscCategory> dcElement => dcElement.Value,
|
|
Element<InternalProgram> ipElement => ipElement.Value,
|
|
Element<MediaType> mtElement => mtElement.Value,
|
|
RedumpSystemComboBoxItem rsElement => rsElement.Value,
|
|
Element<Region> reValue => reValue.Value,
|
|
_ => null,
|
|
};
|
|
}
|
|
}
|
|
}
|