support for .NET framework 3.5

Still have bugs
This commit is contained in:
NaBian committed 2019-01-21 00:43:10 +08:00
1 parent 5878039e21
commit 7d6b491f25
704 files changed
+48273 -33

No files matched your search

@@ -0,0 +1,27 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return value;
}
}
}
@@ -0,0 +1,32 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace HandyControl.Tools.Converter
{
public class Boolean2StrConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
if (parameter is string str)
{
var arr = str.Split(';');
if (arr.Length > 1)
{
return boolValue ? arr[1] : arr[0];
}
return "";
}
return "";
}
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,20 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data;
namespace HandyControl.Tools.Converter
{
public class BooleanArr2VisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
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;
}
}
return arr.All(item => item) ? Visibility.Visible : Visibility.Collapsed;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,39 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string str)
{
try
{
if (ColorConverter.ConvertFromString(str) is Color color)
{
return new SolidColorBrush(color);
}
}
catch
{
return parameter;
}
return parameter;
}
return parameter;
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
namespace HandyControl.Tools.Converter
{
public class Color2HexStrConverter : 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 "";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string str)
{
try
{
if (ColorConverter.ConvertFromString(str) is Color color)
{
return new SolidColorBrush(color);
}
}
catch
{
return new SolidColorBrush(default(Color));
}
return new SolidColorBrush(default(Color));
}
return new SolidColorBrush(default(Color));
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace HandyControl.Tools.Converter
{
public class Int2StrConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int 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 NotImplementedException();
}
}
}
@@ -0,0 +1,52 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,16 @@
using System;
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);
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,116 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace HandyControl.Tools.Converter
{
/// <summary>
/// The ProgressBarHighlightConverter class
/// </summary>
public class ProgressBarHighlightConverter : IMultiValueConverter
{
/// <summary>
/// Creates the brush for the ProgressBar
/// </summary>
/// <param name="values">ForegroundBrush, IsIndeterminate, Width, Height</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Brush for the ProgressBar</returns>
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//
// Parameter Validation
//
var doubleType = typeof(double);
if (values == null ||
values.Length != 3 ||
values[0] == null ||
values[1] == null ||
values[2] == null ||
!(values[0] is Brush) ||
!doubleType.IsInstanceOfType(values[1]) ||
!doubleType.IsInstanceOfType(values[2]))
return null;
//
// Conversion
//
var brush = (Brush) values[0];
var width = (double) values[1];
var height = (double) values[2];
// if an invalid height, return a null brush
if (width <= 0.0 || double.IsInfinity(width) || double.IsNaN(width) ||
height <= 0.0 || double.IsInfinity(height) || double.IsNaN(height))
return null;
var newBrush = new DrawingBrush();
// Create a Drawing Brush that is 2x longer than progress bar track
//
// +-------------+..............
// | highlight | empty :
// +-------------+.............:
//
// This brush will animate to the right.
var twiceWidth = width * 2.0;
// Set the viewport and viewbox to the 2*size of the progress region
newBrush.Viewport = newBrush.Viewbox = new Rect(-width, 0, twiceWidth, height);
newBrush.ViewportUnits = newBrush.ViewboxUnits = BrushMappingMode.Absolute;
newBrush.TileMode = TileMode.None;
newBrush.Stretch = Stretch.None;
var myDrawing = new DrawingGroup();
var myDrawingContext = myDrawing.Open();
// Draw the highlight
myDrawingContext.DrawRectangle(brush, null, new Rect(-width, 0, width, height));
// Animate the Translation
var translateTime = TimeSpan.FromSeconds(twiceWidth / 200.0); // travel at 200px /second
var pauseTime = TimeSpan.FromSeconds(1.0); // pause 1 second between animations
var animation = new DoubleAnimationUsingKeyFrames
{
BeginTime = TimeSpan.Zero,
Duration = new Duration(translateTime + pauseTime),
RepeatBehavior = RepeatBehavior.Forever
};
animation.KeyFrames.Add(new LinearDoubleKeyFrame(twiceWidth, translateTime));
var translation = new TranslateTransform();
// Set the animation to the XProperty
translation.BeginAnimation(TranslateTransform.XProperty, animation);
// Set the animated translation on the brush
newBrush.Transform = translation;
myDrawingContext.Close();
newBrush.Drawing = myDrawing;
return newBrush;
}
/// <summary>
/// Not Supported
/// </summary>
/// <param name="value">value, as produced by target</param>
/// <param name="targetTypes">target types</param>
/// <param name="parameter">converter parameter</param>
/// <param name="culture">culture information</param>
/// <returns>Nothing</returns>
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => null;
}
}
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace HandyControl.Tools.Converter
{
public class Source2ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null ? new Uri(value.ToString(), UriKind.Relative) : null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null && (Visibility)value == Visibility.Visible;
}
}
}
@@ -0,0 +1,20 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null && (Visibility)value == Visibility.Collapsed;
}
}
}
@@ -0,0 +1,20 @@
using System;
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;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null && (Visibility)value == Visibility.Collapsed;
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace HandyControl.Tools.Converter
{
public class TreeViewItemMarginConverter: IValueConverter
{
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))
{
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 NotImplementedException();
}
}
}