mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-28 12:13:25 +08:00
1.01
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class BoolVisibilityConverter : IValueConverter
|
||||
{
|
||||
#region IValueConverter Members
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var visibility = value as bool?;
|
||||
var visible = parameter as string;
|
||||
|
||||
if (visibility != null && visible != null)
|
||||
{
|
||||
if (visibility == true && visible == "true")
|
||||
{
|
||||
return Visibility.Visible;
|
||||
}
|
||||
if (visibility == false && visible == "false")
|
||||
{
|
||||
return Visibility.Visible;
|
||||
}
|
||||
}
|
||||
else if (visibility != null)
|
||||
{
|
||||
if (visibility == true)
|
||||
{
|
||||
return Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class ConverterBoolToValueMap : MarkupExtension, IValueConverter
|
||||
{
|
||||
public override object ProvideValue(System.IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ConverterBoolToValueMap
|
||||
{
|
||||
FromType = this.FromType ?? typeof(char),
|
||||
TargetType = this.TargetType ?? typeof(bool),
|
||||
Parameter = this.Parameter
|
||||
};
|
||||
}
|
||||
|
||||
public object Parameter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type TargetType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type FromType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#region IValueConverter Members
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var result = DependencyProperty.UnsetValue;
|
||||
if (value == null) return result;
|
||||
if (value is bool)
|
||||
{
|
||||
if ((bool)value)
|
||||
result = parameter;
|
||||
else
|
||||
result = this.Parameter;
|
||||
if (result == null || string.IsNullOrWhiteSpace(result.ToString()))
|
||||
return DependencyProperty.UnsetValue;
|
||||
//处理枚举类型
|
||||
if (targetType.IsEnum)
|
||||
result = Enum.Parse(targetType, result as string);
|
||||
else if (targetType.IsValueType)
|
||||
{
|
||||
if (targetType == typeof(Int32))
|
||||
result = System.Convert.ToInt32(result);
|
||||
else if (targetType == typeof(Int16))
|
||||
result = System.Convert.ToInt16(result);
|
||||
else if (targetType == typeof(char))
|
||||
result = result.ToString().First();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return false;
|
||||
|
||||
if (object.Equals(value, parameter))
|
||||
return true;
|
||||
|
||||
return string.Equals(value.ToString(), parameter.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class ConverterValueMapSetToVisibility : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return DependencyProperty.UnsetValue;
|
||||
|
||||
IEnumerable<string> checkList = parameter.ToString().Split('^');
|
||||
|
||||
bool equal = checkList.Contains(value.ToString());
|
||||
|
||||
if (equal)
|
||||
return Visibility.Visible;
|
||||
else
|
||||
return Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object ProvideValue(System.IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ConverterValueMapSetToVisibility
|
||||
{
|
||||
FromType = this.FromType ?? typeof(char),
|
||||
TargetType = this.TargetType ?? typeof(bool),
|
||||
Parameter = this.Parameter
|
||||
};
|
||||
}
|
||||
public object Parameter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type TargetType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type FromType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class ConverterValueMapToBool : MarkupExtension, IValueConverter
|
||||
{
|
||||
public override object ProvideValue(System.IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ConverterValueMapToBool
|
||||
{
|
||||
FromType = this.FromType ?? typeof(char),
|
||||
TargetType = this.TargetType ?? typeof(bool),
|
||||
Parameter = this.Parameter
|
||||
};
|
||||
}
|
||||
|
||||
public object Parameter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type TargetType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type FromType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
#region IValueConverter Members
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return false;
|
||||
|
||||
if (object.Equals(value, parameter))
|
||||
return true;
|
||||
|
||||
return string.Equals(value.ToString(), parameter.ToString());
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
var result = DependencyProperty.UnsetValue;
|
||||
if (value == null) return result;
|
||||
if (value is bool)
|
||||
{
|
||||
if ((bool)value)
|
||||
result = parameter;
|
||||
else
|
||||
result = this.Parameter;
|
||||
if (result == null || string.IsNullOrWhiteSpace(result.ToString()))
|
||||
return DependencyProperty.UnsetValue;
|
||||
//处理枚举类型
|
||||
if (targetType.IsEnum)
|
||||
result = Enum.Parse(targetType, result as string);
|
||||
else if (targetType.IsValueType)
|
||||
{
|
||||
if (targetType == typeof(Int32))
|
||||
result = System.Convert.ToInt32(result);
|
||||
else if (targetType == typeof(Int16))
|
||||
result = System.Convert.ToInt16(result);
|
||||
else if (targetType == typeof(char))
|
||||
result = result.ToString().First();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class ConverterValueMapToVisibility : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return DependencyProperty.UnsetValue;
|
||||
bool equal = string.Equals(value.ToString(), parameter.ToString());
|
||||
|
||||
//true = Visible
|
||||
if (equal)
|
||||
return Visibility.Visible;
|
||||
else
|
||||
return this.Parameter != null && this.Parameter.ToString().ToLower() == Visibility.Hidden.ToString().ToLower() ? Visibility.Hidden : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object ProvideValue(System.IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ConverterValueMapToVisibility
|
||||
{
|
||||
FromType = this.FromType ?? typeof(char),
|
||||
TargetType = this.TargetType ?? typeof(bool),
|
||||
Parameter = this.Parameter
|
||||
};
|
||||
}
|
||||
public object Parameter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type TargetType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type FromType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class ConverterValueSetToOppositeVisibility : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value == null || parameter == null)
|
||||
return DependencyProperty.UnsetValue;
|
||||
|
||||
IEnumerable<string> checkList = parameter.ToString().Split('^');
|
||||
|
||||
bool equal = checkList.Contains(value.ToString());
|
||||
|
||||
if (equal)
|
||||
return Visibility.Collapsed;
|
||||
else
|
||||
return Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override object ProvideValue(System.IServiceProvider serviceProvider)
|
||||
{
|
||||
return new ConverterValueSetToOppositeVisibility
|
||||
{
|
||||
FromType = this.FromType ?? typeof(char),
|
||||
TargetType = this.TargetType ?? typeof(bool),
|
||||
Parameter = this.Parameter
|
||||
};
|
||||
}
|
||||
public object Parameter
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type TargetType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Type FromType
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
176
AIStudio.Wpf.DiagramDesigner/Converters/Converters.cs
Normal file
176
AIStudio.Wpf.DiagramDesigner/Converters/Converters.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
#region Half
|
||||
public class HalfConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var doubleValue = (value as double?).GetValueOrDefault();
|
||||
|
||||
return doubleValue / 2;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region String IsNullOrEmpty
|
||||
public class IsNullOrEmptyConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string)value);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region True -> False
|
||||
public class BoolInverseConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return !(bool)value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region True -> Visible Or Collpased
|
||||
public class BoolToVisibleConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class BoolToInvisibleConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (bool)value ? Visibility.Collapsed : Visibility.Visible;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region object try to convert to image (if is uri)
|
||||
public class IconConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null || !(value.GetType() == typeof(string)))
|
||||
return value;
|
||||
|
||||
var iconString = value as string;
|
||||
|
||||
if (!string.IsNullOrEmpty(iconString) && Uri.IsWellFormedUriString(iconString, UriKind.RelativeOrAbsolute))
|
||||
{
|
||||
var image = new System.Windows.Controls.Image()
|
||||
{
|
||||
Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(iconString, UriKind.RelativeOrAbsolute)),
|
||||
};
|
||||
System.Windows.Media.RenderOptions.SetBitmapScalingMode(image, System.Windows.Media.BitmapScalingMode.HighQuality);
|
||||
return image;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Double -> GridLength
|
||||
public class GridLengthConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var length = value?.ToString();
|
||||
try
|
||||
{
|
||||
return (GridLength)TypeDescriptor.GetConverter(typeof(GridLength)).ConvertFromString(length);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new GridLength(1, GridUnitType.Auto);
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Combiner
|
||||
public class MultiCombinerConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return values.Clone();
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
return new object[] { DependencyProperty.UnsetValue, DependencyProperty.UnsetValue };
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region NotAlignmentCenter
|
||||
public class NotAlignmentCenterConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is HorizontalAlignment)
|
||||
{
|
||||
var alignment = (HorizontalAlignment)value;
|
||||
return alignment != HorizontalAlignment.Center;
|
||||
}
|
||||
else if (value is VerticalAlignment)
|
||||
{
|
||||
var alignment = (VerticalAlignment)value;
|
||||
return alignment != VerticalAlignment.Center;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner.Converters
|
||||
{
|
||||
public class IntToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (object.Equals(value, 0d))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (object.Equals(value, false))
|
||||
return 0d;
|
||||
else
|
||||
return 1d;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user