整理控件库
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal class BackButtonVisibilityToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
not NavigationViewBackButtonVisible _ => Visibility.Collapsed,
|
||||
NavigationViewBackButtonVisible.Collapsed => Visibility.Collapsed,
|
||||
NavigationViewBackButtonVisible.Visible => Visibility.Visible,
|
||||
NavigationViewBackButtonVisible.Auto => Visibility.Visible,
|
||||
_ => Visibility.Collapsed,
|
||||
};
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.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(
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,8 @@ public class BooleanConverter<T> : IValueConverter
|
||||
FalseValue = falseValue;
|
||||
}
|
||||
|
||||
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value is bool boolValue &&
|
||||
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
value is bool boolValue &&
|
||||
boolValue
|
||||
? TrueValue
|
||||
: FalseValue;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal class BrushToColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if(value is SolidColorBrush brush)
|
||||
{
|
||||
return brush.Color;
|
||||
}
|
||||
|
||||
if(value is Color)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
// We draw red to visibly see an invalid bind in the UI.
|
||||
return new Color { A = 255, R = 255, G = 0, B = 0, };
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal class FallbackBrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value switch
|
||||
{
|
||||
SolidColorBrush brush => brush,
|
||||
Color color => new SolidColorBrush(color),
|
||||
_ => new SolidColorBrush(Colors.Red),
|
||||
};
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal 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;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.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(
|
||||
);
|
||||
}
|
||||
@@ -9,11 +9,9 @@ namespace WPFluent.Converters;
|
||||
/// </summary>
|
||||
internal 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)
|
||||
public object? ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{ return null; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
|
||||
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace WPFluent.Converters;
|
||||
|
||||
internal class TextToAsteriskConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ return new string('*', value?.ToString()?.Length ?? 0); }
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
Reference in New Issue
Block a user