添加项目文件。

This commit is contained in:
GG Z
2024-09-22 11:05:41 +08:00
parent fb5d55723a
commit 49ceaae6a8
764 changed files with 78850 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace Wpf.Ui.Extend.Converters;
public class ActualColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var color=(Color)value;
color.ScA = 1;
return color;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace Wpf.Ui.Extend.Converters;
internal class BooleanAllConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
=> values.OfType<bool>().All(b => b);
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
namespace Wpf.Ui.Extend.Converters;
public class BooleanConverter<T> : IValueConverter
{
public BooleanConverter(T trueValue, T falseValue)
{
TrueValue = trueValue;
FalseValue = falseValue;
}
public T TrueValue { get; set; }
public T FalseValue { get; set; }
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
=> value is bool boolValue && boolValue ? TrueValue : FalseValue;
public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> value is T tValue && EqualityComparer<T>.Default.Equals(tValue, TrueValue);
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Wpf.Ui.Extend.Converters;
public class BooleanToVisConverter : BooleanConverter<Visibility>
{
public BooleanToVisConverter() : base(Visibility.Visible, Visibility.Collapsed)
{
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace Wpf.Ui.Extend.Converters;
public 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)
{
return new SolidColorBrush(color);
}
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Wpf.Ui.Extend.Converters;
public class DoubleToPercentageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = (double)value;
return Math.Round(d * 100, MidpointRounding.AwayFromZero);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var str = value.ToString().TrimEnd('%');
if (double.TryParse(str, out var d))
{
return d / 100;
}
return Binding.DoNothing;
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using Wpf.Ui.Extend.Extensions;
using Wpf.Ui.Extend.Models;
namespace Wpf.Ui.Extend.Converters;
/// <summary>
/// 色相转颜色
/// </summary>
public class HsbLinearGradientConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var v = (double)value;
return new LinearGradientBrush(Colors.White, new Hsb(v, 1, 1).ToColor(), 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using Wpf.Ui.Extend.Extensions;
using Wpf.Ui.Extend.Models;
namespace Wpf.Ui.Extend.Converters;
public class HsbToColorConverter : IValueConverter, IMultiValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Hsb hsb) return new SolidColorBrush(hsb.ToColor());
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is SolidColorBrush brush) return brush.Color.ToHsb();
return Binding.DoNothing;
}
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var h = (double)values[0];
var s = (double)values[1];
var b = (double)values[2];
return new SolidColorBrush(new Hsb(h, s, b).ToColor());
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,12 @@
namespace Wpf.Ui.Extend.Converters;
public class InvertBooleanConverter : BooleanConverter<bool>
{
/// <summary>
/// 传bool类型的变量并将值赋值的给返回值的TrueValue和FalseValue,在这里取反
/// </summary>
public InvertBooleanConverter()
: base(false, true)
{
}
}

View File

@@ -0,0 +1,11 @@
using System.Windows;
namespace Wpf.Ui.Extend.Converters;
public class InverterBooleanToVisConverter : BooleanConverter<Visibility>
{
public InverterBooleanToVisConverter() : base(Visibility.Collapsed, Visibility.Visible)
{
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace Wpf.Ui.Extend.Converters;
public class MathRoundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var d = (double)value;
return Math.Round(d, MidpointRounding.AwayFromZero);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var str = value.ToString();
if (double.TryParse(str, out var d))
{
return d;
}
return Binding.DoNothing;
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Data;
namespace Wpf.Ui.Extend.Converters;
/// <summary>
/// 滑动块标签位置
/// </summary>
[ValueConversion(typeof(double), typeof(double), ParameterType = typeof(Orientation))]
internal class SliderValueLabelPositionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter is Orientation orientation && value is double width)
{
const double halfGripWidth = 9.0;
const double margin = 4.0;
return orientation switch
{
Orientation.Horizontal => (-width * 0.5) + halfGripWidth,
Orientation.Vertical => -width - margin,
_ => throw new ArgumentOutOfRangeException()
};
}
return 0.0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
=> throw new NotImplementedException();
}

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using Wpf.Ui.Controls;
namespace Wpf.Ui.Extend.Converters;
public class StringToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.ToString();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string str = value.ToString();
Regex regex = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$");
if (regex.IsMatch(str))
{
var color = ColorConverter.ConvertFromString(str);
return color;
}
return Binding.DoNothing;
}
}
/// <summary>
/// 判断值是否为空
/// </summary>
public class StringIsEmptyConverter : IValueConverter
{
#region IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return string.IsNullOrEmpty(System.Convert.ToString(value));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
#endregion
}