mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-26 03:07:55 +08:00
整理一下项目文件
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
|
||||
public class ArrowPathConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is ArrowPathStyle arrowStyle)
|
||||
{
|
||||
return ArrowPathData.Arrow[(int)arrowStyle];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ArrowSizeConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is ArrowSizeStyle arrowStyle)
|
||||
{
|
||||
return (int)arrowStyle;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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
|
||||
{
|
||||
[ValueConversion(typeof(bool), typeof(Visibility))]
|
||||
public class BoolToVisibilityConverter : IValueConverter
|
||||
{
|
||||
static BoolToVisibilityConverter()
|
||||
{
|
||||
Instance = new BoolToVisibilityConverter();
|
||||
}
|
||||
|
||||
public static BoolToVisibilityConverter Instance
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
78
AIStudio.Wpf.DiagramDesigner/Converters/ClipConverter.cs
Normal file
78
AIStudio.Wpf.DiagramDesigner/Converters/ClipConverter.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class ClipConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
string para = parameter?.ToString();
|
||||
try
|
||||
{
|
||||
if (value is ImageItemViewModel imageItemViewModel)
|
||||
{
|
||||
double xradio = imageItemViewModel.ItemWidth / imageItemViewModel.ImageWidth;
|
||||
double yradio = imageItemViewModel.ItemHeight / imageItemViewModel.ImageHeight;
|
||||
if (para == "Clip")
|
||||
{
|
||||
if (imageItemViewModel.ClipMode == ClipMode.RectangleGeometry)
|
||||
{
|
||||
RectangleGeometry rectangle = new RectangleGeometry();
|
||||
if (imageItemViewModel.ResizeMode == false)
|
||||
{
|
||||
rectangle.Rect = new System.Windows.Rect(imageItemViewModel.ResizeMargin.Left * xradio, imageItemViewModel.ResizeMargin.Top * yradio, imageItemViewModel.ItemWidth, imageItemViewModel.ItemHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
rectangle.Rect = new System.Windows.Rect(imageItemViewModel.ResizeMargin.Left, imageItemViewModel.ResizeMargin.Top , imageItemViewModel.ItemWidth - (imageItemViewModel.ResizeMargin.Left + imageItemViewModel.ResizeMargin.Right), imageItemViewModel.ItemHeight - (imageItemViewModel.ResizeMargin.Top + imageItemViewModel.ResizeMargin.Bottom));
|
||||
}
|
||||
return rectangle;
|
||||
}
|
||||
else if (imageItemViewModel.ClipMode == ClipMode.EllipseGeometry)
|
||||
{
|
||||
EllipseGeometry ellipse = new EllipseGeometry();
|
||||
if (imageItemViewModel.ResizeMode == false)
|
||||
{
|
||||
ellipse.Center = new Point(imageItemViewModel.ResizeMargin.Left * xradio + imageItemViewModel.ItemWidth / 2, imageItemViewModel.ResizeMargin.Top * yradio + imageItemViewModel.ItemHeight / 2);
|
||||
ellipse.RadiusX = imageItemViewModel.ItemWidth / 2;
|
||||
ellipse.RadiusY = imageItemViewModel.ItemHeight / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ellipse.Center = new Point(imageItemViewModel.ResizeMargin.Left + (imageItemViewModel.ItemWidth - imageItemViewModel.ResizeMargin.Left - imageItemViewModel.ResizeMargin.Right) / 2, imageItemViewModel.ResizeMargin.Top + (imageItemViewModel.ItemHeight - imageItemViewModel.ResizeMargin.Top - imageItemViewModel.ResizeMargin.Bottom)/ 2);
|
||||
ellipse.RadiusX = (imageItemViewModel.ItemWidth - imageItemViewModel.ResizeMargin.Left - imageItemViewModel.ResizeMargin.Right) / 2;
|
||||
ellipse.RadiusY = (imageItemViewModel.ItemHeight - imageItemViewModel.ResizeMargin.Top - imageItemViewModel.ResizeMargin.Bottom) / 2;
|
||||
}
|
||||
return ellipse;
|
||||
}
|
||||
}
|
||||
else if (para == "Margin")
|
||||
{
|
||||
if (imageItemViewModel.ResizeMode == false)
|
||||
{
|
||||
return new Thickness(-imageItemViewModel.ResizeMargin.Left * xradio, -imageItemViewModel.ResizeMargin.Top * yradio, -imageItemViewModel.ResizeMargin.Right * xradio, -imageItemViewModel.ResizeMargin.Bottom * yradio);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Thickness();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
218
AIStudio.Wpf.DiagramDesigner/Converters/ColorBrushConverter.cs
Normal file
218
AIStudio.Wpf.DiagramDesigner/Converters/ColorBrushConverter.cs
Normal file
@@ -0,0 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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
|
||||
{
|
||||
public class ColorBrushConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
Brush brush = null;
|
||||
if (value is Color)
|
||||
{
|
||||
brush = new SolidColorBrush((Color)value);
|
||||
}
|
||||
else if (value is ColorObject colorObject)
|
||||
{
|
||||
if (colorObject.BrushType == BrushType.None)
|
||||
brush = new SolidColorBrush(Colors.Transparent);
|
||||
else if (colorObject.BrushType == BrushType.SolidColorBrush)
|
||||
brush = new SolidColorBrush(colorObject.Color);
|
||||
else if (colorObject.BrushType == BrushType.LinearGradientBrush)
|
||||
{
|
||||
Point startPoint;
|
||||
Point endPoint;
|
||||
if (colorObject.LinearOrientation == LinearOrientation.LeftToRight)
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftTopToRightBottom)
|
||||
{
|
||||
startPoint = new Point(0, 0);
|
||||
endPoint = new Point(1, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.TopToBottom)
|
||||
{
|
||||
startPoint = new Point(0.5, 0);
|
||||
endPoint = new Point(0.5, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightTopToLeftBottom)
|
||||
{
|
||||
startPoint = new Point(1, 0);
|
||||
endPoint = new Point(0, 1);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightToLeft)
|
||||
{
|
||||
startPoint = new Point(1, 0.5);
|
||||
endPoint = new Point(0, 0.5);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.RightBottomToLeftTop)
|
||||
{
|
||||
startPoint = new Point(1, 1);
|
||||
endPoint = new Point(0, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.BottomToTop)
|
||||
{
|
||||
startPoint = new Point(0.5, 1);
|
||||
endPoint = new Point(0.5, 0);
|
||||
}
|
||||
else if (colorObject.LinearOrientation == LinearOrientation.LeftBottomToRightTop)
|
||||
{
|
||||
startPoint = new Point(0, 1);
|
||||
endPoint = new Point(1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
startPoint = new Point(0, 0.5);
|
||||
endPoint = new Point(1, 0.5);
|
||||
}
|
||||
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = startPoint;
|
||||
myBrush.EndPoint = endPoint;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.RadialGradientBrush)
|
||||
{
|
||||
Point center;
|
||||
Point gradientOrigin;
|
||||
double radiusX;
|
||||
double radiusY;
|
||||
|
||||
if (colorObject.RadialOrientation == RadialOrientation.LeftTop)
|
||||
{
|
||||
center = new Point(0, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightTop)
|
||||
{
|
||||
center = new Point(1, 0);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.RightBottom)
|
||||
{
|
||||
center = new Point(1, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else if (colorObject.RadialOrientation == RadialOrientation.LeftBottom)
|
||||
{
|
||||
center = new Point(0, 1);
|
||||
gradientOrigin = center;
|
||||
radiusX = 1;
|
||||
radiusY = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
center = new Point(0.5, 0.5);
|
||||
gradientOrigin = center;
|
||||
radiusX = 0.5;
|
||||
radiusY = 0.5;
|
||||
}
|
||||
|
||||
RadialGradientBrush myBrush = new RadialGradientBrush();
|
||||
myBrush.Center = center;
|
||||
myBrush.GradientOrigin = gradientOrigin;
|
||||
myBrush.RadiusX = radiusX;
|
||||
myBrush.RadiusY = radiusY;
|
||||
if (colorObject.GradientStop != null)
|
||||
{
|
||||
foreach (var stop in colorObject.GradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
|
||||
RotateTransform rotateTransform = new RotateTransform(colorObject.Angle, 0.5, 0.5);
|
||||
myBrush.RelativeTransform = rotateTransform;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.ImageBrush)
|
||||
{
|
||||
ImageBrush myBrush = new ImageBrush();
|
||||
myBrush.ImageSource = new BitmapImage(new Uri(colorObject.Image, UriKind.Absolute));
|
||||
brush = myBrush;
|
||||
}
|
||||
else if (colorObject.BrushType == BrushType.DrawingBrush)
|
||||
{
|
||||
DrawingBrush myBrush = new DrawingBrush();
|
||||
|
||||
GeometryDrawing backgroundSquare =
|
||||
new GeometryDrawing(
|
||||
Brushes.White,
|
||||
null,
|
||||
new RectangleGeometry(new Rect(0, 0, 100, 100)));
|
||||
|
||||
GeometryGroup aGeometryGroup = new GeometryGroup();
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(0, 0, 50, 50)));
|
||||
aGeometryGroup.Children.Add(new RectangleGeometry(new Rect(50, 50, 50, 50)));
|
||||
|
||||
LinearGradientBrush checkerBrush = new LinearGradientBrush();
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Black, 0.0));
|
||||
checkerBrush.GradientStops.Add(new System.Windows.Media.GradientStop(Colors.Gray, 1.0));
|
||||
|
||||
GeometryDrawing checkers = new GeometryDrawing(checkerBrush, null, aGeometryGroup);
|
||||
|
||||
DrawingGroup checkersDrawingGroup = new DrawingGroup();
|
||||
checkersDrawingGroup.Children.Add(backgroundSquare);
|
||||
checkersDrawingGroup.Children.Add(checkers);
|
||||
|
||||
myBrush.Drawing = checkersDrawingGroup;
|
||||
myBrush.Viewport = new Rect(0, 0, 0.25, 0.25);
|
||||
myBrush.TileMode = TileMode.Tile;
|
||||
|
||||
brush = myBrush;
|
||||
}
|
||||
if (brush != null)
|
||||
{
|
||||
brush.Opacity = colorObject.Opacity;
|
||||
}
|
||||
}
|
||||
else if (value is ObservableCollection<GradientStop> gradientStop)
|
||||
{
|
||||
LinearGradientBrush myBrush = new LinearGradientBrush();
|
||||
myBrush.StartPoint = new Point(0, 0.5);
|
||||
myBrush.EndPoint = new Point(1, 0.5);
|
||||
if (gradientStop != null)
|
||||
{
|
||||
foreach (var stop in gradientStop)
|
||||
{
|
||||
myBrush.GradientStops.Add(new System.Windows.Media.GradientStop(stop.Color, stop.Offset));
|
||||
}
|
||||
}
|
||||
brush = myBrush;
|
||||
}
|
||||
|
||||
return brush;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
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
|
||||
{
|
||||
public class ConectorOrientationConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is string)
|
||||
{
|
||||
string str = value as string;
|
||||
|
||||
return -5 - (str.Length * 4);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using AIStudio.Wpf.DiagramDesigner;
|
||||
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
|
||||
{
|
||||
public class ConectorValueConverter : IMultiValueConverter
|
||||
{
|
||||
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (values == null || values.Length < 1)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (values[0] is double && values[1] is ValueTypePoint)
|
||||
{
|
||||
double connectorValue = (double)values[0];
|
||||
ValueTypePoint valueTypePoint = (ValueTypePoint)values[1];
|
||||
|
||||
if (valueTypePoint == ValueTypePoint.Bool)
|
||||
{
|
||||
return (connectorValue == 0) ? "F" : "T";
|
||||
}
|
||||
else if (valueTypePoint == ValueTypePoint.Int)
|
||||
{
|
||||
return connectorValue.ToString("0");
|
||||
}
|
||||
else
|
||||
{
|
||||
return connectorValue.ToString("f3");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
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
|
||||
{
|
||||
public class ConnectionDataConverter : IMultiValueConverter
|
||||
{
|
||||
static ConnectionDataConverter()
|
||||
{
|
||||
Instance = new ConnectionDataConverter();
|
||||
}
|
||||
|
||||
public static ConnectionDataConverter Instance
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
List<PointInfoBase> points = (List<PointInfoBase>)values[0];
|
||||
PathGeometry pathGeometry = new PathGeometry();
|
||||
PathFigure figure = new PathFigure();
|
||||
figure.StartPoint = points[0];
|
||||
if (values[1]?.ToString() == DrawMode.RadiusConnectingLine.ToString())
|
||||
{
|
||||
for (var i = 0; i < points.Count - 1; i++)
|
||||
{
|
||||
int current = i, last = i - 1, next = i + 1, next2 = i + 2;
|
||||
if (last == -1)
|
||||
{
|
||||
last = 0;
|
||||
}
|
||||
if (next == points.Count)
|
||||
{
|
||||
next = points.Count - 1;
|
||||
}
|
||||
if (next2 == points.Count)
|
||||
{
|
||||
next2 = points.Count - 1;
|
||||
}
|
||||
var bzs = SegmentHelper.GetBezierSegment(points[current], points[last], points[next], points[next2]);
|
||||
figure.Segments.Add(bzs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < points.Count; i++)
|
||||
{
|
||||
|
||||
LineSegment arc = new LineSegment(points[i], true);
|
||||
figure.Segments.Add(arc);
|
||||
}
|
||||
}
|
||||
|
||||
pathGeometry.Figures.Add(figure);
|
||||
return pathGeometry;
|
||||
}
|
||||
|
||||
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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
|
||||
{
|
||||
[ValueConversion(typeof(List<Point>), typeof(PathSegmentCollection))]
|
||||
public class ConnectionPathConverter : IValueConverter
|
||||
{
|
||||
static ConnectionPathConverter()
|
||||
{
|
||||
Instance = new ConnectionPathConverter();
|
||||
}
|
||||
|
||||
public static ConnectionPathConverter Instance
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
List<PointInfoBase> points = (List<PointInfoBase>)value;
|
||||
PointCollection pointCollection = new PointCollection();
|
||||
if (points != null)
|
||||
{
|
||||
foreach (var point in points)
|
||||
{
|
||||
pointCollection.Add(point);
|
||||
}
|
||||
}
|
||||
return pointCollection;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
85
AIStudio.Wpf.DiagramDesigner/Converters/DoubleToThickness.cs
Normal file
85
AIStudio.Wpf.DiagramDesigner/Converters/DoubleToThickness.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class EnumDescriptionConverter : IValueConverter
|
||||
{
|
||||
#region constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnumDescriptionConverter"/> class.
|
||||
/// </summary>
|
||||
public EnumDescriptionConverter()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IValueConverter
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
if (value is Enum)
|
||||
{
|
||||
return ((Enum)value).GetDescription();
|
||||
}
|
||||
else
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
37
AIStudio.Wpf.DiagramDesigner/Converters/ImageUrlConverter.cs
Normal file
37
AIStudio.Wpf.DiagramDesigner/Converters/ImageUrlConverter.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
[ValueConversion(typeof(string), typeof(ImageSource))]
|
||||
public class ImageUrlConverter : IValueConverter
|
||||
{
|
||||
static ImageUrlConverter()
|
||||
{
|
||||
Instance = new ImageUrlConverter();
|
||||
}
|
||||
|
||||
public static ImageUrlConverter Instance
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
Uri imagePath = new Uri(value.ToString(), UriKind.RelativeOrAbsolute);
|
||||
ImageSource source = new BitmapImage(imagePath);
|
||||
return source;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public class InvertBoolConverter : 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(IServiceProvider serviceProvider)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
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 !(bool)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
AIStudio.Wpf.DiagramDesigner/Converters/LineDashConverter.cs
Normal file
24
AIStudio.Wpf.DiagramDesigner/Converters/LineDashConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
|
||||
public class LineDashConverter : IValueConverter
|
||||
{
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
if (value is LineDashStyle arrowStyle)
|
||||
{
|
||||
return StrokeDashArray.Dash[(int)arrowStyle];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
/// <summary>
|
||||
/// 这是一个颠倒黑白的世界
|
||||
/// </summary>
|
||||
public sealed class TrueToFalseConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var v = (bool)value;
|
||||
return !v;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user