Files
ShrlAlgoToolkit/Melskin/Converters/Internal/SymbolToCharConverter.cs
2026-02-17 22:17:13 +08:00

33 lines
1.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Globalization;
using System.Windows.Data;
using Melskin.Assets;
namespace Melskin.Converters.Internal;
/// <summary>
/// SymbolToCharConverter 类用于将 MaterialSymbol 枚举值转换为其对应的字符表示。此转换器实现了 IValueConverter 接口,主要用于 WPF 应用程序中绑定数据时进行类型转换。
/// </summary>
/// <remarks>
/// 该类提供了一个静态实例 Instance可以直接在 XAML 中引用以避免重复创建对象。转换逻辑仅支持从 MaterialSymbol 到字符串的单向转换Convert 方法不支持反向转换ConvertBack 方法未实现)。
/// </remarks>
internal class SymbolToCharConverter : IValueConverter
{
public static readonly SymbolToCharConverter Instance = new();
/// <inheritdoc />
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is MaterialSymbol symbol)
{
return ((char)(int)symbol).ToString();
}
return string.Empty;
}
/// <inheritdoc />
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}