更新整理
This commit is contained in:
@@ -9,17 +9,17 @@ internal class AnimationFactorToValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(values[0] is not double completeValue)
|
||||
if (values[0] is not double completeValue)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(values[1] is not double factor)
|
||||
if (values[1] is not double factor)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
if(parameter is "negative")
|
||||
if (parameter is "negative")
|
||||
{
|
||||
factor = -factor;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal class BoolToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ return value is true ? Visibility.Visible : Visibility.Collapsed; }
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
@@ -4,12 +4,12 @@ using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
public class ColorToBrushConverter : IValueConverter
|
||||
internal class ColorToBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
//var color = (SelectedColor)value;
|
||||
if(value is System.Windows.Media.Color color)
|
||||
if (value is System.Windows.Media.Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
public sealed class CornerRadiusFilterConverter : DependencyObject, IValueConverter
|
||||
{
|
||||
public CornerRadiusFilterKind Filter { get; set; }
|
||||
|
||||
public double Scale { get; set; } = 1d;
|
||||
|
||||
public static CornerRadius Convert(CornerRadius radius, CornerRadiusFilterKind filterKind)
|
||||
{
|
||||
var result = radius;
|
||||
switch (filterKind)
|
||||
{
|
||||
case CornerRadiusFilterKind.Top:
|
||||
result.BottomLeft = 0.0;
|
||||
result.BottomRight = 0.0;
|
||||
break;
|
||||
|
||||
case CornerRadiusFilterKind.Right:
|
||||
result.TopLeft = 0.0;
|
||||
result.BottomLeft = 0.0;
|
||||
break;
|
||||
|
||||
case CornerRadiusFilterKind.Bottom:
|
||||
result.TopLeft = 0.0;
|
||||
result.TopRight = 0.0;
|
||||
break;
|
||||
|
||||
case CornerRadiusFilterKind.Left:
|
||||
result.TopRight = 0.0;
|
||||
result.BottomRight = 0.0;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is CornerRadius radius)
|
||||
{
|
||||
var scale = Scale;
|
||||
if (!double.IsNaN(scale))
|
||||
{
|
||||
radius.TopLeft *= scale;
|
||||
radius.TopRight *= scale;
|
||||
radius.BottomRight *= scale;
|
||||
radius.BottomLeft *= scale;
|
||||
}
|
||||
|
||||
var filter = Filter;
|
||||
if (filter == CornerRadiusFilterKind.TopLeftValue || filter == CornerRadiusFilterKind.BottomRightValue)
|
||||
{
|
||||
return GetDoubleValue(radius, filter);
|
||||
}
|
||||
|
||||
return Convert(radius, filter);
|
||||
}
|
||||
|
||||
return new CornerRadius(0.0);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return new CornerRadius(0.0);
|
||||
}
|
||||
|
||||
private double GetDoubleValue(CornerRadius radius, CornerRadiusFilterKind filterKind)
|
||||
{
|
||||
return filterKind switch
|
||||
{
|
||||
CornerRadiusFilterKind.TopLeftValue => radius.TopLeft,
|
||||
CornerRadiusFilterKind.BottomRightValue => radius.BottomRight,
|
||||
_ => 0.0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum CornerRadiusFilterKind
|
||||
{
|
||||
None,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Left,
|
||||
TopLeftValue,
|
||||
BottomRightValue
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
public class DoubleToPercentageConverter : IValueConverter
|
||||
internal class DoubleToPercentageConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
@@ -15,7 +15,7 @@ public class DoubleToPercentageConverter : IValueConverter
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var str = value.ToString().TrimEnd('%');
|
||||
if(double.TryParse(str, out var d))
|
||||
if (double.TryParse(str, out var d))
|
||||
{
|
||||
return d / 100;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
|
||||
using WPFluent.Extensions;
|
||||
using WPFluent.Models;
|
||||
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
|
||||
using WPFluent.Controls;
|
||||
using WPFluent.Extensions;
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// 色相转颜色
|
||||
/// </summary>
|
||||
public class HsbLinearGradientConverter : IValueConverter
|
||||
internal class HsbLinearGradientConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
|
||||
using WPFluent.Extensions;
|
||||
using WPFluent.Models;
|
||||
|
||||
using System;
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
using WPFluent.Controls;
|
||||
using WPFluent.Extensions;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Converts HSB color values to SolidColorBrush and vice versa. Supports single and multi-value conversions.
|
||||
/// </summary>
|
||||
public class HsbToColorConverter : IValueConverter, IMultiValueConverter
|
||||
internal class HsbToColorConverter : IValueConverter, IMultiValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is Hsb hsb)
|
||||
if (value is Hsb hsb)
|
||||
return new SolidColorBrush(hsb.ToColor());
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
@@ -29,7 +31,7 @@ public class HsbToColorConverter : IValueConverter, IMultiValueConverter
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is SolidColorBrush brush)
|
||||
if (value is SolidColorBrush brush)
|
||||
return brush.Color.ToHsb();
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace WPFluent.Converters;
|
||||
/// <summary>
|
||||
/// Tries to convert <see cref="SymbolRegular"/> and <seealso cref="SymbolFilled"/> to <see cref="SymbolIcon"/>.
|
||||
/// </summary>
|
||||
public class IconElementConverter : TypeConverter
|
||||
internal class IconElementConverter : TypeConverter
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// Converts an <see cref="IconSourceElement"/> to an <see cref="IconElement"/>.
|
||||
/// </summary>
|
||||
public class IconSourceElementConverter : IValueConverter
|
||||
internal class IconSourceElementConverter : IValueConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a value to an <see cref="IconElement"/>.
|
||||
@@ -22,7 +23,7 @@ public class IconSourceElementConverter : IValueConverter
|
||||
/// <returns>The converted <see cref="IconElement"/>.</returns>
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is IconSourceElement iconSourceElement)
|
||||
if (value is IconSourceElement iconSourceElement)
|
||||
{
|
||||
return iconSourceElement.CreateIconElement();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
public class MathRoundConverter : IValueConverter
|
||||
internal class MathRoundConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
@@ -15,7 +15,7 @@ public class MathRoundConverter : IValueConverter
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var str = value.ToString();
|
||||
if(double.TryParse(str, out var d))
|
||||
if (double.TryParse(str, out var d))
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace WPFluent.Converters;
|
||||
/// <summary>
|
||||
/// 判断值是否为空
|
||||
/// </summary>
|
||||
public class StringIsEmptyConverter : IValueConverter
|
||||
internal class StringIsEmptyConverter : IValueConverter
|
||||
{
|
||||
#region IValueConverter 成员
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
public class StringToColorConverter : IValueConverter
|
||||
internal class StringToColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{ return value.ToString(); }
|
||||
@@ -15,7 +15,7 @@ public class StringToColorConverter : IValueConverter
|
||||
{
|
||||
string str = value.ToString();
|
||||
Regex regex = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$");
|
||||
if(regex.IsMatch(str))
|
||||
if (regex.IsMatch(str))
|
||||
{
|
||||
var color = ColorConverter.ConvertFromString(str);
|
||||
return color;
|
||||
|
||||
Reference in New Issue
Block a user