chore: use file-scoped namespace
This commit is contained in:
1 parent
99d2fafb72
commit
bbf1b7d4c6
748 files changed
+57929
-58678
No files matched your search
@@ -2,26 +2,25 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Boolean2BooleanReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
return !boolValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
public class Boolean2BooleanReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
return !boolValue;
|
||||
}
|
||||
return value;
|
||||
return !boolValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
return !boolValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class Boolean2StringConverter : IValueConverter
|
||||
{
|
||||
public class Boolean2StringConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
if (value is bool boolValue)
|
||||
{
|
||||
if (value is bool boolValue)
|
||||
if (parameter is string str)
|
||||
{
|
||||
if (parameter is string str)
|
||||
var arr = str.Split(';');
|
||||
if (arr.Length > 1)
|
||||
{
|
||||
var arr = str.Split(';');
|
||||
if (arr.Length > 1)
|
||||
{
|
||||
return boolValue ? arr[1] : arr[0];
|
||||
}
|
||||
return "";
|
||||
return boolValue ? arr[1] : arr[0];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Boolean2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (bool) value ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class Boolean2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (bool) value ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -5,36 +5,35 @@ using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class BooleanArr2BooleanConverter : IMultiValueConverter
|
||||
{
|
||||
public class BooleanArr2BooleanConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
if (values == null)
|
||||
{
|
||||
if (values == null)
|
||||
return ValueBoxes.FalseBox;
|
||||
}
|
||||
|
||||
var arr = new List<bool>();
|
||||
foreach (var item in values)
|
||||
{
|
||||
if (item is bool boolValue)
|
||||
{
|
||||
arr.Add(boolValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ValueBoxes.FalseBox;
|
||||
}
|
||||
|
||||
var arr = new List<bool>();
|
||||
foreach (var item in values)
|
||||
{
|
||||
if (item is bool boolValue)
|
||||
{
|
||||
arr.Add(boolValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ValueBoxes.FalseBox;
|
||||
}
|
||||
}
|
||||
|
||||
return ValueBoxes.BooleanBox(arr.All(item => item));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return ValueBoxes.BooleanBox(arr.All(item => item));
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -5,35 +5,34 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class BooleanArr2VisibilityConverter : IMultiValueConverter
|
||||
{
|
||||
public class BooleanArr2VisibilityConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
if (values == null)
|
||||
{
|
||||
if (values == null)
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
var arr = new List<bool>();
|
||||
foreach (var item in values)
|
||||
{
|
||||
if (item is bool boolValue)
|
||||
{
|
||||
arr.Add(boolValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
var arr = new List<bool>();
|
||||
foreach (var item in values)
|
||||
{
|
||||
if (item is bool boolValue)
|
||||
{
|
||||
arr.Add(boolValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
return arr.All(item => item) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return arr.All(item => item) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -6,31 +6,30 @@ using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class BorderCircularClipConverter : IMultiValueConverter
|
||||
{
|
||||
public class BorderCircularClipConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
if (values.Length == 3 && values[0] is double width && values[1] is double height && values[2] is CornerRadius radius)
|
||||
{
|
||||
if (values.Length == 3 && values[0] is double width && values[1] is double height && values[2] is CornerRadius radius)
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return Geometry.Empty;
|
||||
}
|
||||
|
||||
var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
|
||||
clip.Freeze();
|
||||
|
||||
return clip;
|
||||
return Geometry.Empty;
|
||||
}
|
||||
|
||||
return DependencyProperty.UnsetValue;
|
||||
var clip = new RectangleGeometry(new Rect(0, 0, width, height), radius.TopLeft, radius.TopLeft);
|
||||
clip.Freeze();
|
||||
|
||||
return clip;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,28 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class BorderCircularConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length == 2 && values[0] is double width && values[1] is double height)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return new CornerRadius();
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
var min = Math.Min(width, height);
|
||||
return new CornerRadius(min / 2);
|
||||
public class BorderCircularConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length == 2 && values[0] is double width && values[1] is double height)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return new CornerRadius();
|
||||
}
|
||||
|
||||
return DependencyProperty.UnsetValue;
|
||||
var min = Math.Min(width, height);
|
||||
return new CornerRadius(min / 2);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -4,47 +4,46 @@ using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class BorderClipConverter : IMultiValueConverter
|
||||
{
|
||||
public class BorderClipConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
if (values.Length == 3 && values[0] is double width && values[1] is double height && values[2] is CornerRadius radius)
|
||||
{
|
||||
if (values.Length == 3 && values[0] is double width && values[1] is double height && values[2] is CornerRadius radius)
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return Geometry.Empty;
|
||||
}
|
||||
|
||||
var clip = new PathGeometry
|
||||
{
|
||||
Figures = new PathFigureCollection
|
||||
{
|
||||
new(new Point(radius.TopLeft, 0), new PathSegment[]
|
||||
{
|
||||
new LineSegment(new Point(width - radius.TopRight, 0), false),
|
||||
new ArcSegment(new Point(width, radius.TopRight), new Size(radius.TopRight, radius.TopRight), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(width, height - radius.BottomRight), false),
|
||||
new ArcSegment(new Point(width - radius.BottomRight, height), new Size(radius.BottomRight, radius.BottomRight), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(radius.BottomLeft, height), false),
|
||||
new ArcSegment(new Point(0, height - radius.BottomLeft), new Size(radius.BottomLeft, radius.BottomLeft), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(0, radius.TopLeft), false),
|
||||
new ArcSegment(new Point(radius.TopLeft, 0), new Size(radius.TopLeft, radius.TopLeft), 90, false, SweepDirection.Clockwise, false),
|
||||
}, false)
|
||||
}
|
||||
};
|
||||
clip.Freeze();
|
||||
|
||||
return clip;
|
||||
return Geometry.Empty;
|
||||
}
|
||||
|
||||
return DependencyProperty.UnsetValue;
|
||||
var clip = new PathGeometry
|
||||
{
|
||||
Figures = new PathFigureCollection
|
||||
{
|
||||
new(new Point(radius.TopLeft, 0), new PathSegment[]
|
||||
{
|
||||
new LineSegment(new Point(width - radius.TopRight, 0), false),
|
||||
new ArcSegment(new Point(width, radius.TopRight), new Size(radius.TopRight, radius.TopRight), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(width, height - radius.BottomRight), false),
|
||||
new ArcSegment(new Point(width - radius.BottomRight, height), new Size(radius.BottomRight, radius.BottomRight), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(radius.BottomLeft, height), false),
|
||||
new ArcSegment(new Point(0, height - radius.BottomLeft), new Size(radius.BottomLeft, radius.BottomLeft), 90, false, SweepDirection.Clockwise, false),
|
||||
new LineSegment(new Point(0, radius.TopLeft), false),
|
||||
new ArcSegment(new Point(radius.TopLeft, 0), new Size(radius.TopLeft, radius.TopLeft), 90, false, SweepDirection.Clockwise, false),
|
||||
}, false)
|
||||
}
|
||||
};
|
||||
clip.Freeze();
|
||||
|
||||
return clip;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -6,130 +6,129 @@ using System.Security;
|
||||
using System.Text;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class ColLayoutConverter : TypeConverter
|
||||
{
|
||||
public class ColLayoutConverter : TypeConverter
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType)
|
||||
{
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType)
|
||||
switch (Type.GetTypeCode(sourceType))
|
||||
{
|
||||
switch (Type.GetTypeCode(sourceType))
|
||||
{
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt64:
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
case TypeCode.String:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType) =>
|
||||
destinationType == typeof(InstanceDescriptor) || destinationType == typeof(string);
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
|
||||
{
|
||||
if (source == null) throw GetConvertFromException(null);
|
||||
|
||||
return source switch
|
||||
{
|
||||
string s => FromString(s, cultureInfo),
|
||||
double d => new ColLayout((int) d),
|
||||
_ => new ColLayout(Convert.ToInt32(source, cultureInfo))
|
||||
};
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
|
||||
{
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
if (destinationType == null) throw new ArgumentNullException(nameof(destinationType));
|
||||
|
||||
if (!(value is ColLayout th)) throw new ArgumentException("UnexpectedParameterType");
|
||||
|
||||
if (destinationType == typeof(string)) return ToString(th, cultureInfo);
|
||||
if (destinationType == typeof(InstanceDescriptor))
|
||||
{
|
||||
var ci = typeof(ColLayout).GetConstructor(new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) });
|
||||
return new InstanceDescriptor(ci, new object[] { th.Xs, th.Sm, th.Md, th.Lg, th.Xl, th.Xxl });
|
||||
}
|
||||
|
||||
throw new ArgumentException("CannotConvertType");
|
||||
}
|
||||
|
||||
private static string ToString(ColLayout th, CultureInfo cultureInfo)
|
||||
{
|
||||
var listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);
|
||||
|
||||
// Initial capacity [128] is an estimate based on a sum of:
|
||||
// 72 = 6x double (twelve digits is generous for the range of values likely)
|
||||
// 4 = 4x separator characters
|
||||
var sb = new StringBuilder(128);
|
||||
|
||||
sb.Append(th.Xs.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Sm.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Md.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Lg.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Xl.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Xxl.ToString(cultureInfo));
|
||||
return th.ToString();
|
||||
}
|
||||
|
||||
private static ColLayout FromString(string s, CultureInfo cultureInfo)
|
||||
{
|
||||
var th = new TokenizerHelper(s, cultureInfo);
|
||||
var lengths = new int[6];
|
||||
var i = 0;
|
||||
|
||||
while (th.NextToken())
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
i = 7; // Set i to a bad value.
|
||||
break;
|
||||
}
|
||||
|
||||
lengths[i] = th.GetCurrentToken().Value<int>();
|
||||
i++;
|
||||
}
|
||||
|
||||
return i switch
|
||||
{
|
||||
1 => new ColLayout(lengths[0]),
|
||||
2 => new ColLayout { Xs = lengths[0], Sm = lengths[1] },
|
||||
3 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2] },
|
||||
4 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2], Lg = lengths[3] },
|
||||
5 => new ColLayout
|
||||
{
|
||||
Xs = lengths[0],
|
||||
Sm = lengths[1],
|
||||
Md = lengths[2],
|
||||
Lg = lengths[3],
|
||||
Xl = lengths[4]
|
||||
},
|
||||
6 => new ColLayout
|
||||
{
|
||||
Xs = lengths[0],
|
||||
Sm = lengths[1],
|
||||
Md = lengths[2],
|
||||
Lg = lengths[3],
|
||||
Xl = lengths[4],
|
||||
Xxl = lengths[5]
|
||||
},
|
||||
_ => throw new FormatException("InvalidStringColLayout")
|
||||
};
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt64:
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
case TypeCode.String:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType) =>
|
||||
destinationType == typeof(InstanceDescriptor) || destinationType == typeof(string);
|
||||
|
||||
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source)
|
||||
{
|
||||
if (source == null) throw GetConvertFromException(null);
|
||||
|
||||
return source switch
|
||||
{
|
||||
string s => FromString(s, cultureInfo),
|
||||
double d => new ColLayout((int) d),
|
||||
_ => new ColLayout(Convert.ToInt32(source, cultureInfo))
|
||||
};
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value, Type destinationType)
|
||||
{
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
if (destinationType == null) throw new ArgumentNullException(nameof(destinationType));
|
||||
|
||||
if (!(value is ColLayout th)) throw new ArgumentException("UnexpectedParameterType");
|
||||
|
||||
if (destinationType == typeof(string)) return ToString(th, cultureInfo);
|
||||
if (destinationType == typeof(InstanceDescriptor))
|
||||
{
|
||||
var ci = typeof(ColLayout).GetConstructor(new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int) });
|
||||
return new InstanceDescriptor(ci, new object[] { th.Xs, th.Sm, th.Md, th.Lg, th.Xl, th.Xxl });
|
||||
}
|
||||
|
||||
throw new ArgumentException("CannotConvertType");
|
||||
}
|
||||
|
||||
private static string ToString(ColLayout th, CultureInfo cultureInfo)
|
||||
{
|
||||
var listSeparator = TokenizerHelper.GetNumericListSeparator(cultureInfo);
|
||||
|
||||
// Initial capacity [128] is an estimate based on a sum of:
|
||||
// 72 = 6x double (twelve digits is generous for the range of values likely)
|
||||
// 4 = 4x separator characters
|
||||
var sb = new StringBuilder(128);
|
||||
|
||||
sb.Append(th.Xs.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Sm.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Md.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Lg.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Xl.ToString(cultureInfo));
|
||||
sb.Append(listSeparator);
|
||||
sb.Append(th.Xxl.ToString(cultureInfo));
|
||||
return th.ToString();
|
||||
}
|
||||
|
||||
private static ColLayout FromString(string s, CultureInfo cultureInfo)
|
||||
{
|
||||
var th = new TokenizerHelper(s, cultureInfo);
|
||||
var lengths = new int[6];
|
||||
var i = 0;
|
||||
|
||||
while (th.NextToken())
|
||||
{
|
||||
if (i >= 6)
|
||||
{
|
||||
i = 7; // Set i to a bad value.
|
||||
break;
|
||||
}
|
||||
|
||||
lengths[i] = th.GetCurrentToken().Value<int>();
|
||||
i++;
|
||||
}
|
||||
|
||||
return i switch
|
||||
{
|
||||
1 => new ColLayout(lengths[0]),
|
||||
2 => new ColLayout { Xs = lengths[0], Sm = lengths[1] },
|
||||
3 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2] },
|
||||
4 => new ColLayout { Xs = lengths[0], Sm = lengths[1], Md = lengths[2], Lg = lengths[3] },
|
||||
5 => new ColLayout
|
||||
{
|
||||
Xs = lengths[0],
|
||||
Sm = lengths[1],
|
||||
Md = lengths[2],
|
||||
Lg = lengths[3],
|
||||
Xl = lengths[4]
|
||||
},
|
||||
6 => new ColLayout
|
||||
{
|
||||
Xs = lengths[0],
|
||||
Sm = lengths[1],
|
||||
Md = lengths[2],
|
||||
Lg = lengths[3],
|
||||
Xl = lengths[4],
|
||||
Xxl = lengths[5]
|
||||
},
|
||||
_ => throw new FormatException("InvalidStringColLayout")
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -3,37 +3,36 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Color2ChannelAConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
{
|
||||
return brush.Color.A;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
public class Color2ChannelAConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
{
|
||||
if (value is string str)
|
||||
return brush.Color.A;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
if (ColorConverter.ConvertFromString(str) is Color color)
|
||||
{
|
||||
if (ColorConverter.ConvertFromString(str) is Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return parameter;
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return parameter;
|
||||
}
|
||||
return parameter;
|
||||
}
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,38 +3,37 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Color2HexStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
{
|
||||
var color = brush.Color;
|
||||
return color.A < 255 ? $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}" : $"#{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
public class Color2HexStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is SolidColorBrush brush)
|
||||
{
|
||||
if (value is string str)
|
||||
var color = brush.Color;
|
||||
return color.A < 255 ? $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}" : $"#{color.R:X2}{color.G:X2}{color.B:X2}";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
if (ColorConverter.ConvertFromString(str) is Color color)
|
||||
{
|
||||
if (ColorConverter.ConvertFromString(str) is Color color)
|
||||
{
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new SolidColorBrush(default);
|
||||
return new SolidColorBrush(color);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new SolidColorBrush(default);
|
||||
}
|
||||
return new SolidColorBrush(default);
|
||||
}
|
||||
return new SolidColorBrush(default);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,32 +3,31 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class CornerRadiusSplitConverter : IValueConverter
|
||||
{
|
||||
public class CornerRadiusSplitConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
if (value is CornerRadius cornerRadius)
|
||||
{
|
||||
if (value is CornerRadius cornerRadius)
|
||||
if (parameter is string str)
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var arr = str.Split(',');
|
||||
if (arr.Length != 4) return cornerRadius;
|
||||
var arr = str.Split(',');
|
||||
if (arr.Length != 4) return cornerRadius;
|
||||
|
||||
return new CornerRadius(
|
||||
arr[0].Equals("1") ? cornerRadius.TopLeft : 0,
|
||||
arr[1].Equals("1") ? cornerRadius.TopRight : 0,
|
||||
arr[2].Equals("1") ? cornerRadius.BottomRight : 0,
|
||||
arr[3].Equals("1") ? cornerRadius.BottomLeft : 0);
|
||||
}
|
||||
return new CornerRadius(
|
||||
arr[0].Equals("1") ? cornerRadius.TopLeft : 0,
|
||||
arr[1].Equals("1") ? cornerRadius.TopRight : 0,
|
||||
arr[2].Equals("1") ? cornerRadius.BottomRight : 0,
|
||||
arr[3].Equals("1") ? cornerRadius.BottomLeft : 0);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
+32
-33
@@ -4,46 +4,43 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class DataGridSelectAllButtonVisibilityConverter : IMultiValueConverter
|
||||
{
|
||||
public class DataGridSelectAllButtonVisibilityConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
if (values == null)
|
||||
{
|
||||
if (values == null)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (values.Length != 2)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
if (values.Length != 2)
|
||||
{
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
if (values[0] is DataGridHeadersVisibility headersVisibility)
|
||||
if (values[0] is DataGridHeadersVisibility headersVisibility)
|
||||
{
|
||||
if (values[1] is bool showButton)
|
||||
{
|
||||
if (values[1] is bool showButton)
|
||||
if (headersVisibility == DataGridHeadersVisibility.All)
|
||||
{
|
||||
if (headersVisibility == DataGridHeadersVisibility.All)
|
||||
{
|
||||
return showButton ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
return showButton ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
else if (values[0] is bool showButton)
|
||||
{
|
||||
if (values[1] is DataGridHeadersVisibility visibility)
|
||||
{
|
||||
if (visibility == DataGridHeadersVisibility.All)
|
||||
{
|
||||
return showButton ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
else if (values[0] is bool showButton)
|
||||
{
|
||||
if (values[1] is DataGridHeadersVisibility visibility)
|
||||
{
|
||||
if (visibility == DataGridHeadersVisibility.All)
|
||||
{
|
||||
return showButton ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
@@ -52,9 +49,11 @@ namespace HandyControl.Tools.Converter
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,26 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class Double2GridLengthConverter : IValueConverter
|
||||
{
|
||||
public class Double2GridLengthConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
if (value is double doubleValue)
|
||||
{
|
||||
if (value is double doubleValue)
|
||||
if (double.IsNaN(doubleValue) || double.IsInfinity(doubleValue))
|
||||
{
|
||||
if (double.IsNaN(doubleValue) || double.IsInfinity(doubleValue))
|
||||
{
|
||||
return new GridLength(1.0, GridUnitType.Star);
|
||||
}
|
||||
return new GridLength(doubleValue);
|
||||
return new GridLength(1.0, GridUnitType.Star);
|
||||
}
|
||||
|
||||
return new GridLength(0);
|
||||
return new GridLength(doubleValue);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return new GridLength(0);
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,28 @@ using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class DoubleMinConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double doubleValue)
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var minValue = str.Value<double>();
|
||||
return doubleValue < minValue ? minValue : doubleValue;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
return doubleValue < .0 ? .0 : doubleValue;
|
||||
public class DoubleMinConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is double doubleValue)
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var minValue = str.Value<double>();
|
||||
return doubleValue < minValue ? minValue : doubleValue;
|
||||
}
|
||||
|
||||
return .0;
|
||||
return doubleValue < .0 ? .0 : doubleValue;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return .0;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -2,37 +2,36 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Int2StringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (int.TryParse(value.ToString(), out var intValue))
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var arr = str.Split(';');
|
||||
if (arr.Length > intValue)
|
||||
{
|
||||
return arr[intValue];
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
return intValue;
|
||||
public class Int2StringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (int.TryParse(value.ToString(), out var intValue))
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var arr = str.Split(';');
|
||||
if (arr.Length > intValue)
|
||||
{
|
||||
return arr[intValue];
|
||||
}
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -2,51 +2,50 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Long2FileSizeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return Properties.Langs.Lang.UnknownSize;
|
||||
if (value is long intValue)
|
||||
{
|
||||
if (intValue < 0)
|
||||
{
|
||||
return Properties.Langs.Lang.UnknownSize;
|
||||
}
|
||||
if (intValue < 1024)
|
||||
{
|
||||
return $"{intValue} B";
|
||||
}
|
||||
if (intValue < 1048576)
|
||||
{
|
||||
return $"{intValue / 1024.0:0.00} KB";
|
||||
}
|
||||
if (intValue < 1073741824)
|
||||
{
|
||||
return $"{intValue / 1048576.0:0.00} MB";
|
||||
}
|
||||
if (intValue < 1099511627776)
|
||||
{
|
||||
return $"{intValue / 1073741824.0:0.00} GB";
|
||||
}
|
||||
if (intValue < 1125899906842624)
|
||||
{
|
||||
return $"{intValue / 1099511627776.0:0.00} TB";
|
||||
}
|
||||
if (intValue < 1152921504606847000)
|
||||
{
|
||||
return $"{intValue / 1125899906842624.0:0.00} PB";
|
||||
}
|
||||
return Properties.Langs.Lang.TooLarge;
|
||||
}
|
||||
return Properties.Langs.Lang.Unknown;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
public class Long2FileSizeConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return Properties.Langs.Lang.UnknownSize;
|
||||
if (value is long intValue)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
if (intValue < 0)
|
||||
{
|
||||
return Properties.Langs.Lang.UnknownSize;
|
||||
}
|
||||
if (intValue < 1024)
|
||||
{
|
||||
return $"{intValue} B";
|
||||
}
|
||||
if (intValue < 1048576)
|
||||
{
|
||||
return $"{intValue / 1024.0:0.00} KB";
|
||||
}
|
||||
if (intValue < 1073741824)
|
||||
{
|
||||
return $"{intValue / 1048576.0:0.00} MB";
|
||||
}
|
||||
if (intValue < 1099511627776)
|
||||
{
|
||||
return $"{intValue / 1073741824.0:0.00} GB";
|
||||
}
|
||||
if (intValue < 1125899906842624)
|
||||
{
|
||||
return $"{intValue / 1099511627776.0:0.00} TB";
|
||||
}
|
||||
if (intValue < 1152921504606847000)
|
||||
{
|
||||
return $"{intValue / 1125899906842624.0:0.00} PB";
|
||||
}
|
||||
return Properties.Langs.Lang.TooLarge;
|
||||
}
|
||||
return Properties.Langs.Lang.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -4,33 +4,32 @@ using System.Windows.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class Number2PercentageConverter : IMultiValueConverter
|
||||
{
|
||||
public class Number2PercentageConverter : IMultiValueConverter
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values == null || values.Length != 2) return .0;
|
||||
if (values == null || values.Length != 2) return .0;
|
||||
|
||||
var obj1 = values[0];
|
||||
var obj2 = values[1];
|
||||
var obj1 = values[0];
|
||||
var obj2 = values[1];
|
||||
|
||||
if (obj1 == null || obj2 == null) return .0;
|
||||
if (obj1 == null || obj2 == null) return .0;
|
||||
|
||||
var str1 = values[0].ToString();
|
||||
var str2 = values[1].ToString();
|
||||
var str1 = values[0].ToString();
|
||||
var str2 = values[1].ToString();
|
||||
|
||||
var v1 = str1.Value<double>();
|
||||
var v2 = str2.Value<double>();
|
||||
var v1 = str1.Value<double>();
|
||||
var v2 = str2.Value<double>();
|
||||
|
||||
if (MathHelper.IsVerySmall(v2)) return 100.0;
|
||||
if (MathHelper.IsVerySmall(v2)) return 100.0;
|
||||
|
||||
return v1 / v2 * 100;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return v1 / v2 * 100;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Object2BooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => !(value is null);
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class Object2BooleanConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => !(value is null);
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Object2StringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value?.ToString();
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class Object2StringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value?.ToString();
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Object2VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class Object2VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class Object2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class Object2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,29 +3,28 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class RectangleCircularConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length == 2 && values[0] is double width && values[1] is double height)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return .0;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
var min = Math.Min(width, height);
|
||||
return min / 2;
|
||||
public class RectangleCircularConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (values.Length == 2 && values[0] is double width && values[1] is double height)
|
||||
{
|
||||
if (width < double.Epsilon || height < double.Epsilon)
|
||||
{
|
||||
return .0;
|
||||
}
|
||||
|
||||
return DependencyProperty.UnsetValue;
|
||||
var min = Math.Min(width, height);
|
||||
return min / 2;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class String2VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string) value) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (Visibility) value == Visibility.Collapsed;
|
||||
}
|
||||
public class String2VisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string) value) ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (Visibility) value == Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
@@ -3,18 +3,17 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
{
|
||||
public class String2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string) value) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (Visibility) value == Visibility.Collapsed;
|
||||
}
|
||||
public class String2VisibilityReConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string) value) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null && (Visibility) value == Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
@@ -3,32 +3,31 @@ using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class ThicknessSplitConverter : IValueConverter
|
||||
{
|
||||
public class ThicknessSplitConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
if (value is Thickness thickness)
|
||||
{
|
||||
if (value is Thickness thickness)
|
||||
if (parameter is string str)
|
||||
{
|
||||
if (parameter is string str)
|
||||
{
|
||||
var arr = str.Split(',');
|
||||
if (arr.Length != 4) return thickness;
|
||||
var arr = str.Split(',');
|
||||
if (arr.Length != 4) return thickness;
|
||||
|
||||
return new Thickness(
|
||||
arr[0].Equals("1") ? thickness.Left : 0,
|
||||
arr[1].Equals("1") ? thickness.Top : 0,
|
||||
arr[2].Equals("1") ? thickness.Right : 0,
|
||||
arr[3].Equals("1") ? thickness.Bottom : 0);
|
||||
}
|
||||
return new Thickness(
|
||||
arr[0].Equals("1") ? thickness.Left : 0,
|
||||
arr[1].Equals("1") ? thickness.Top : 0,
|
||||
arr[2].Equals("1") ? thickness.Right : 0,
|
||||
arr[3].Equals("1") ? thickness.Bottom : 0);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,24 @@ using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Converter
|
||||
namespace HandyControl.Tools.Converter;
|
||||
|
||||
public class TreeViewItemMarginConverter : IValueConverter
|
||||
{
|
||||
public class TreeViewItemMarginConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
var left = 0.0;
|
||||
UIElement element = value as TreeViewItem;
|
||||
while (element != null && element.GetType() != typeof(TreeView))
|
||||
{
|
||||
var left = 0.0;
|
||||
UIElement element = value as TreeViewItem;
|
||||
while (element != null && element.GetType() != typeof(TreeView))
|
||||
{
|
||||
element = (UIElement) VisualTreeHelper.GetParent(element);
|
||||
if (element is TreeViewItem)
|
||||
left += 19.0;
|
||||
}
|
||||
return new Thickness(left, 0, 0, 0);
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
element = (UIElement) VisualTreeHelper.GetParent(element);
|
||||
if (element is TreeViewItem)
|
||||
left += 19.0;
|
||||
}
|
||||
return new Thickness(left, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user