mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using System;
|
|
using System.Windows;
|
|
using OwlCore.AbstractUI.Models;
|
|
using OwlCore.AbstractUI.ViewModels;
|
|
using CommunityToolkit.Diagnostics;
|
|
using System.Windows.Data;
|
|
using System.Globalization;
|
|
|
|
namespace OwlCore.Wpf.AbstractUI.Themes
|
|
{
|
|
/// <summary>
|
|
/// Selects the template that is used for an <see cref="AbstractButton"/> based on the <see cref="AbstractButton.Type"/>.
|
|
/// </summary>
|
|
public class AbstractButtonTemplateSelector : IValueConverter
|
|
{
|
|
/// <summary>
|
|
/// The data template used to a display an <see cref="AbstractButton"/> with a generic style.
|
|
/// </summary>
|
|
public Style? GenericStyle { get; set; }
|
|
|
|
/// <summary>
|
|
/// The data template used to a display an <see cref="AbstractButton"/> with a confirmation style.
|
|
/// </summary>
|
|
public Style? ConfirmStyle { get; set; }
|
|
|
|
/// <summary>
|
|
/// The data template used to a display an <see cref="AbstractButton"/> with a deletion style.
|
|
/// </summary>
|
|
public Style? DeleteStyle { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var type = AbstractButtonType.Generic;
|
|
|
|
if (value is AbstractButtonType vType)
|
|
type = vType;
|
|
if (value is AbstractButtonViewModel buttonViewModel)
|
|
type = buttonViewModel.Type;
|
|
else if (value is AbstractButton button)
|
|
type = button.Type;
|
|
|
|
return type switch
|
|
{
|
|
AbstractButtonType.Generic => GenericStyle ?? ThrowHelper.ThrowArgumentNullException<Style>(),
|
|
AbstractButtonType.Confirm => ConfirmStyle ?? GenericStyle ?? ThrowHelper.ThrowArgumentNullException<Style>(),
|
|
AbstractButtonType.Cancel => DeleteStyle ?? GenericStyle ?? ThrowHelper.ThrowArgumentNullException<Style>(),
|
|
_ => throw new NotImplementedException(),
|
|
};
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|