命名调整
This commit is contained in:
@@ -9,7 +9,7 @@ public class CornerRadiusToDoubleConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is CornerRadius))
|
||||
if (value is not CornerRadius)
|
||||
{
|
||||
return default(double);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is double))
|
||||
if (value is not double)
|
||||
{
|
||||
return default(CornerRadius);
|
||||
}
|
||||
|
||||
36
AntdWpf/Converters/GenericConverterExtension.cs
Normal file
36
AntdWpf/Converters/GenericConverterExtension.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AntdWpf.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// 构造单例的Converter的markup
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// 示例代码:
|
||||
/// <code>
|
||||
/// <![CDATA[<TextBlock Text="{Binding Value, Converter={local:GenericConverterExtension Type={x:Type local:MyValueConverter}}}" />]]>
|
||||
/// </code>
|
||||
/// </example>
|
||||
public class GenericConverterExtension : MarkupExtension
|
||||
{
|
||||
public Type Type { get; set; }
|
||||
|
||||
private static readonly Dictionary<Type, object> _instances = new();
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (Type == null || !typeof(IValueConverter).IsAssignableFrom(Type)|| !typeof(IMultiValueConverter).IsAssignableFrom(Type))
|
||||
throw new InvalidOperationException("类型必须是值转换器");
|
||||
|
||||
if (!_instances.TryGetValue(Type, out var instance))
|
||||
_instances[Type] = instance = Activator.CreateInstance(Type);
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is Thickness))
|
||||
if (value is not Thickness)
|
||||
{
|
||||
return default(double);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user