mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-07 17:56:35 +08:00
线条控件
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public static class IsSelectedProps
|
||||
{
|
||||
#region IsSelected
|
||||
|
||||
public static readonly DependencyProperty IsSelectedProperty =
|
||||
DependencyProperty.RegisterAttached("IsSelected", typeof(bool), typeof(IsSelectedProps),
|
||||
new FrameworkPropertyMetadata(false));
|
||||
|
||||
public static bool GetIsSelected(DependencyObject d)
|
||||
{
|
||||
return (bool)d.GetValue(IsSelectedProperty);
|
||||
}
|
||||
|
||||
public static void SetIsSelected(DependencyObject d, bool value)
|
||||
{
|
||||
d.SetValue(IsSelectedProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
53
AIStudio.Wpf.DiagramDesigner/Converters/MathConverter.cs
Normal file
53
AIStudio.Wpf.DiagramDesigner/Converters/MathConverter.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
public enum MathOperation
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide
|
||||
}
|
||||
|
||||
public sealed class MathConverter : IValueConverter
|
||||
{
|
||||
public MathOperation Operation
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
try
|
||||
{
|
||||
double value1 = System.Convert.ToDouble(value, CultureInfo.InvariantCulture);
|
||||
double value2 = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
|
||||
switch (Operation)
|
||||
{
|
||||
case MathOperation.Add:
|
||||
return value1 + value2;
|
||||
case MathOperation.Divide:
|
||||
return value1 / value2;
|
||||
case MathOperation.Multiply:
|
||||
return value1 * value2;
|
||||
case MathOperation.Subtract:
|
||||
return value1 - value2;
|
||||
default:
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -527,60 +527,7 @@
|
||||
</ContextMenu>
|
||||
</Grid.ContextMenu>
|
||||
|
||||
<s:LineControl x:Name="line"/>
|
||||
|
||||
<Canvas HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch">
|
||||
<!--<Path x:Name="line" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}">
|
||||
<Path.Data>
|
||||
<MultiBinding Converter="{x:Static s:ConnectionPathConverter.Instance}">
|
||||
<Binding Path="PathGeneratorResult"/>
|
||||
</MultiBinding>
|
||||
</Path.Data>
|
||||
</Path>-->
|
||||
|
||||
<Path x:Name="rightarrow"
|
||||
Data="{Binding ColorViewModel.RightArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Height="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Width="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Stretch="Fill"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform x:Name="rightrot" Angle="{Binding EndAngle}"/>
|
||||
<TranslateTransform X="{Binding EndPoint.X}" Y="{Binding EndPoint.Y}"/>
|
||||
</TransformGroup>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
|
||||
<Path x:Name="leftarrow"
|
||||
Data="{Binding ColorViewModel.LeftArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
Fill="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Height="{Binding ColorViewModel.LeftArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Width="{Binding ColorViewModel.LeftArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Canvas.Left="{Binding StartPoint.X}"
|
||||
Canvas.Top="{Binding StartPoint.Y}"
|
||||
Stretch="Fill"
|
||||
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform x:Name="leftrot" Angle="{Binding StartAngle}"/>
|
||||
<TranslateTransform X="{Binding StartPoint.X}" Y="{Binding StartPoint.Y}"/>
|
||||
</TransformGroup>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
</Canvas>
|
||||
<s:LineControl x:Name="line"/>
|
||||
|
||||
<!-- PART_DragThumb -->
|
||||
<c:DragThumb x:Name="PART_DragThumb"
|
||||
@@ -643,18 +590,6 @@
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Value="True"
|
||||
Binding="{Binding IsSelected}">
|
||||
<!--<Setter TargetName="line"
|
||||
Property="Stroke"
|
||||
Value="Black" />-->
|
||||
<Setter TargetName="line"
|
||||
Property="IsSelected"
|
||||
Value="True" />
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Stroke"
|
||||
Value="Black" />
|
||||
<Setter TargetName="rightarrow"
|
||||
Property="Fill"
|
||||
Value="Black" />
|
||||
<Setter TargetName="PART_VerticesContainer"
|
||||
Property="Visibility"
|
||||
Value="Visible"/>
|
||||
@@ -666,16 +601,6 @@
|
||||
Property="Visibility"
|
||||
Value="Visible"/>
|
||||
</DataTrigger>
|
||||
|
||||
<!--右箭头-->
|
||||
<DataTrigger Binding="{Binding Path=ColorViewModel.RightArrowPathStyle}" Value="None">
|
||||
<Setter TargetName="rightarrow" Property="Visibility" Value="Hidden"/>
|
||||
</DataTrigger>
|
||||
|
||||
<!--左箭头-->
|
||||
<DataTrigger Binding="{Binding Path=ColorViewModel.LeftArrowPathStyle}" Value="None">
|
||||
<Setter TargetName="leftarrow" Property="Visibility" Value="Hidden"/>
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
|
||||
@@ -9,12 +9,33 @@
|
||||
<UserControl.Resources>
|
||||
<s:ColorBrushConverter x:Key="ColorBrushConverter" />
|
||||
<s:LineDashConverter x:Key="LineDashConverter"/>
|
||||
<s:ArrowPathConverter x:Key="ArrowPathConverter"/>
|
||||
<s:ArrowSizeConverter x:Key="ArrowSizeConverter"/>
|
||||
<s:MathConverter x:Key="MathAddConverter" Operation="Add" />
|
||||
<Style x:Key="LineStyle" TargetType="Path">
|
||||
<Setter Property="Stroke" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Value="True" Binding="{Binding IsSelected}">
|
||||
<Setter Property="Stroke" Value="Black"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<Style x:Key="ArrowStyle" TargetType="Path">
|
||||
<Setter Property="Stroke" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>
|
||||
<Setter Property="Fill" Value="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Value="True" Binding="{Binding IsSelected}">
|
||||
<Setter Property="Stroke" Value="Black"/>
|
||||
<Setter Property="Fill" Value="Black"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Canvas x:Name="rootCanvas">
|
||||
<Path x:Name="line" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}">
|
||||
<Path x:Name="line" StrokeThickness="{Binding ColorViewModel.LineWidth}"
|
||||
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}"
|
||||
Style="{StaticResource LineStyle}">
|
||||
<Path.Data>
|
||||
<MultiBinding Converter="{x:Static s:ConnectionPathConverter.Instance}">
|
||||
<Binding Path="PathGeneratorResult"/>
|
||||
@@ -22,16 +43,48 @@
|
||||
</Path.Data>
|
||||
</Path>
|
||||
|
||||
<!--<Path x:Name="ball" Width="5" Height="5" Stretch="Fill" Fill="#eee">
|
||||
<Path.Data>
|
||||
<EllipseGeometry Center="100,100"
|
||||
RadiusX="100"
|
||||
RadiusY="100">
|
||||
</EllipseGeometry>
|
||||
</Path.Data>
|
||||
</Path>-->
|
||||
<Path x:Name="rightarrow"
|
||||
Data="{Binding ColorViewModel.RightArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
Height="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Width="{Binding ColorViewModel.RightArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Stretch="Fill"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Style="{StaticResource ArrowStyle}">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform x:Name="rightrot" Angle="{Binding EndAngle}"/>
|
||||
<TranslateTransform X="{Binding EndPoint.X}" Y="{Binding EndPoint.Y}"/>
|
||||
</TransformGroup>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
|
||||
<Ellipse x:Name="ball" Fill="Red" Width="5" Height="5" Panel.ZIndex="1" />
|
||||
<Path x:Name="leftarrow"
|
||||
Data="{Binding ColorViewModel.LeftArrowPathStyle,Converter={StaticResource ArrowPathConverter}}"
|
||||
Visibility="{Binding Path=IsFullConnection, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"
|
||||
Height="{Binding ColorViewModel.LeftArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Width="{Binding ColorViewModel.LeftArrowSizeStyle, Converter={StaticResource ArrowSizeConverter}}"
|
||||
Canvas.Left="{Binding StartPoint.X}"
|
||||
Canvas.Top="{Binding StartPoint.Y}"
|
||||
Stretch="Fill"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Style="{StaticResource ArrowStyle}">
|
||||
<Path.RenderTransform>
|
||||
<TransformGroup>
|
||||
<RotateTransform x:Name="leftrot" Angle="{Binding StartAngle}"/>
|
||||
<TranslateTransform X="{Binding StartPoint.X}" Y="{Binding StartPoint.Y}"/>
|
||||
</TransformGroup>
|
||||
</Path.RenderTransform>
|
||||
</Path>
|
||||
|
||||
<Ellipse x:Name="ball" Fill="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
|
||||
Width="{Binding ColorViewModel.LineWidth,Converter={StaticResource MathAddConverter},ConverterParameter=4}"
|
||||
Height="{Binding ColorViewModel.LineWidth,Converter={StaticResource MathAddConverter},ConverterParameter=4}"
|
||||
Panel.ZIndex="1" />
|
||||
</Canvas>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -20,24 +20,6 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
/// </summary>
|
||||
public partial class LineControl : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
|
||||
nameof(IsSelected), typeof(bool), typeof(LineControl), new FrameworkPropertyMetadata(
|
||||
false, OnIsSelectedChanged));
|
||||
|
||||
private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (object.Equals(e.NewValue, true))
|
||||
{
|
||||
(d as LineControl).line.Stroke = Brushes.Black;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => (bool)GetValue(IsSelectedProperty);
|
||||
set => SetValue(IsSelectedProperty, value);
|
||||
}
|
||||
|
||||
public LineControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
@@ -56,8 +56,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
if (Root != null && Root.ColorViewModel != null)
|
||||
{
|
||||
this.ColorViewModel = CopyHelper.Mapper(Root.ColorViewModel);
|
||||
this.ColorViewModel = CopyHelper.Mapper(Root.ColorViewModel);
|
||||
}
|
||||
this.ColorViewModel.FillColor.Color = Colors.Red;
|
||||
if (sinkConnectorInfo is FullyCreatedConnectorInfo sink && sink.DataItem.ShowArrow == false)
|
||||
{
|
||||
this.ColorViewModel.RightArrowPathStyle = ArrowPathStyle.None;
|
||||
@@ -714,7 +715,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
label.IsSelected = true;
|
||||
Labels.Add(label);
|
||||
|
||||
var paths = Labels.Count > 0 ? PathGeneratorResult.Paths.Select(p => new SvgPath(p)).ToArray() : Array.Empty<SvgPath>();
|
||||
var paths = Labels.Count > 0 ? PathGeneratorResult?.Paths.Select(p => new SvgPath(p)).ToArray() : Array.Empty<SvgPath>();
|
||||
label.UpdatePosition(paths);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,9 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
public void UpdatePosition(SvgPath[] paths)
|
||||
{
|
||||
if (paths == null)
|
||||
return;
|
||||
|
||||
var position = FindPosition(paths);
|
||||
if (position == null)
|
||||
return;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
ColorViewModel = new ColorViewModel()
|
||||
{
|
||||
LineColor = new ColorObject() { Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x80) },
|
||||
FillColor = new ColorObject() { Color = Colors.Lavender },
|
||||
FillColor = new ColorObject() { Color = Colors.White },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user