整理整理

This commit is contained in:
艾竹
2023-01-25 15:58:05 +08:00
parent 4c5d535aad
commit b7af3534a2
84 changed files with 190 additions and 702 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
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();
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using AIStudio.Wpf.DiagramDesigner.Additionals.Controls;
using AIStudio.Wpf.DiagramDesigner;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class CountShiftConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values != null && values.Length > 2)
{
var diagram = values[0] as AIStudio.Wpf.DiagramDesigner.DiagramControl;
var zoomValue = (double)values[1];
var pageunit = (PageUnit)values[2];
var unit = Unit.Cm;
if (pageunit > PageUnit.km)
{
unit = Unit.Inch;
}
Vector vector = System.Windows.Media.VisualTreeHelper.GetOffset(diagram);
if (parameter?.ToString() == "Y")
{
var value = 0 - (unit == Unit.Cm? DipHelper.DipToCm(vector.Y - 20) : DipHelper.DipToInch(vector.Y - 20))/ zoomValue;
return value;
}
else
{
var value = 0 - (unit == Unit.Cm ? DipHelper.DipToCm(vector.X - 20) : DipHelper.DipToInch(vector.X - 20)) / zoomValue;
return value;
}
}
return 0;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,85 @@
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class DoubleToThickness : IValueConverter
{
public object Convert(object value, System.Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if (parameter != null)
{
switch (parameter.ToString())
{
case "Left":
return new Thickness(System.Convert.ToDouble(value), 0, 0, 0);
case "Top":
return new Thickness(0, System.Convert.ToDouble(value), 0, 0);
case "Right":
return new Thickness(0, 0, System.Convert.ToDouble(value), 0);
case "Buttom":
return new Thickness(0, 0, 0, System.Convert.ToDouble(value));
case "LeftTop":
return new Thickness(System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0, 0);
case "LeftButtom":
return new Thickness(System.Convert.ToDouble(value), 0, 0, System.Convert.ToDouble(value));
case "RightTop":
return new Thickness(0, System.Convert.ToDouble(value), System.Convert.ToDouble(value), 0);
case "RigthButtom":
return new Thickness(0, 0, System.Convert.ToDouble(value), System.Convert.ToDouble(value));
case "LeftRight":
return new Thickness(System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value), 0);
case "TopButtom":
return new Thickness(0, System.Convert.ToDouble(value), 0, System.Convert.ToDouble(value));
default:
return new Thickness(System.Convert.ToDouble(value));
}
}
return new Thickness(System.Convert.ToDouble(value));
}
return new Thickness(0);
}
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
if (parameter != null)
{
switch (parameter.ToString())
{
case "Left":
return ((Thickness)value).Left;
case "Top":
return ((Thickness)value).Top;
case "Right":
return ((Thickness)value).Right;
case "Buttom":
return ((Thickness)value).Bottom;
default:
return ((Thickness)value).Left;
}
}
return ((Thickness)value).Left;
}
return 0.0;
}
}
}

View File

@@ -0,0 +1,50 @@
/**************************************************************************************
Toolkit for WPF
Copyright (C) 2007-2016 Xceed Software Inc.
This program is provided to you under the terms of the Microsoft Public
License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license
For more features, controls, and fast professional support,
pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/
Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids
************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
class HtmlColorConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((value != null) && value is System.Windows.Media.Color)
return new SolidColorBrush((System.Windows.Media.Color)value);
if ((value != null) && value is string str)
{
BrushConverter brushConverter = new BrushConverter();
return (Brush)brushConverter.ConvertFromString(str);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,39 @@
using System.Windows.Data;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class IndentConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double colunwidth = 10;
double left = 0.0;
UIElement element = value as TreeViewItem;
while (element.GetType() != typeof(TreeView))
{
element = (UIElement)VisualTreeHelper.GetParent(element);
if (element.GetType() == typeof(TreeViewItem))
left += colunwidth;
}
return new Thickness(left, 0, 0, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
//选中项索引转换成可见项
public class IntVisibilityConverter : MarkupExtension, IValueConverter
{
/// <summary>
/// Returns the value for the target property of this markup extension.
/// </summary>
/// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
/// <returns>Reference to the instance of this Int32IndexToNumberConverter.</returns>
public override object ProvideValue(System.IServiceProvider serviceProvider)
{
return this;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int && parameter is string) //与参数相同则显示
{
if (parameter.ToString().Contains("^"))
{
var paras = parameter.ToString().Split('^');
foreach(var para in paras)
{
if (value.ToString() == para)
{
return Visibility.Visible;
}
}
return Visibility.Collapsed;
}
else
{
if (value.ToString() == (string)parameter)
{
return Visibility.Visible;
}
}
}
else if (value is int) //无参数则大于0显示
{
if ((int)value > 0)
{
return Visibility.Visible;
}
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class NullableToBooleanConverter : IValueConverter
{
public bool NullValue { get; set; } = false;
public bool NotNullValue { get; set; } = true;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? NullValue : NotNullValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class NullableToVisibilityConverter : IValueConverter
{
public Visibility NullValue { get; set; } = Visibility.Collapsed;
public Visibility NotNullValue { get; set; } = Visibility.Visible;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? NullValue : NotNullValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class NumberConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null)
return 0.ToString("00");
return (System.Convert.ToInt32(value) + 1).ToString("00");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,36 @@
using AIStudio.Wpf.DiagramDesigner.Additionals.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using AIStudio.Wpf.DiagramDesigner;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class RulerUnitConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is PageUnit pageunit)
{
if (pageunit > PageUnit.km)
{
return Unit.Inch;
}
else
{
return Unit.Cm;
}
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class StringPathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is string)
{
Geometry geo = Geometry.Parse(value as string);
return geo;
//GeometryConverter gc = new GeometryConverter();
//return (Geometry)gc.ConvertFromString(value as string);
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
/// <summary>
/// Converts a Thickness to a new Thickness. It's possible to ignore a side With the IgnoreThicknessSide property.
/// </summary>
public class ThicknessBindingConverter : IValueConverter
{
public IgnoreThicknessSideType IgnoreThicknessSide { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Thickness)
{
// yes, we can override it with the parameter value
if (parameter is IgnoreThicknessSideType)
{
this.IgnoreThicknessSide = (IgnoreThicknessSideType)parameter;
}
var orgThickness = (Thickness)value;
switch (this.IgnoreThicknessSide)
{
case IgnoreThicknessSideType.Left:
return new Thickness(0, orgThickness.Top, orgThickness.Right, orgThickness.Bottom);
case IgnoreThicknessSideType.Top:
return new Thickness(orgThickness.Left, 0, orgThickness.Right, orgThickness.Bottom);
case IgnoreThicknessSideType.Right:
return new Thickness(orgThickness.Left, orgThickness.Top, 0, orgThickness.Bottom);
case IgnoreThicknessSideType.Bottom:
return new Thickness(orgThickness.Left, orgThickness.Top, orgThickness.Right, 0);
default:
return orgThickness;
}
}
return default(Thickness);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// for now no back converting
return DependencyProperty.UnsetValue;
}
}
public enum IgnoreThicknessSideType
{
/// <summary>
/// Use all sides.
/// </summary>
None,
/// <summary>
/// Ignore the left side.
/// </summary>
Left,
/// <summary>
/// Ignore the top side.
/// </summary>
Top,
/// <summary>
/// Ignore the right side.
/// </summary>
Right,
/// <summary>
/// Ignore the bottom side.
/// </summary>
Bottom
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters
{
public class ThicknessToDoubleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((Thickness)value).Left;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
internal class DoubleToRightMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness(0, 0, ((double)value), 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
internal class DoubleToLeftMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness(((double)value), 0, 0, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
internal class DoubleToLeftRightMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness((double)value, 0, (double)value, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
}