功能完善
This commit is contained in:
32
NeuWPF/NeoUI/Converters/Internal/SymbolToCharConverter.cs
Normal file
32
NeuWPF/NeoUI/Converters/Internal/SymbolToCharConverter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using NeoUI.Assets;
|
||||
|
||||
namespace NeoUI.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// SymbolToCharConverter 类用于将 MaterialSymbol 枚举值转换为其对应的字符表示。此转换器实现了 IValueConverter 接口,主要用于 WPF 应用程序中绑定数据时进行类型转换。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该类提供了一个静态实例 Instance,可以直接在 XAML 中引用以避免重复创建对象。转换逻辑仅支持从 MaterialSymbol 到字符串的单向转换(Convert 方法),不支持反向转换(ConvertBack 方法未实现)。
|
||||
/// </remarks>
|
||||
public 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user