连接点可以添加文字

This commit is contained in:
艾竹
2023-01-22 21:46:59 +08:00
parent ad227aee0c
commit 4c37fb9772
16 changed files with 371 additions and 122 deletions

View File

@@ -541,11 +541,6 @@
<Canvas.InputBindings>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding EditCommand}" CommandParameter="{Binding }" />
</Canvas.InputBindings>
<!--<Polyline x:Name="poly"
Points="{Binding Path=Vertices, Converter={x:Static s:ConnectionPointConverter.Instance}}"
Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
StrokeThickness="{Binding ColorViewModel.LineWidth}"
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}" />-->
<Path x:Name="poly" Stroke="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
StrokeThickness="{Binding ColorViewModel.LineWidth}"
StrokeDashArray="{Binding ColorViewModel.LineDashStyle,Converter={StaticResource LineDashConverter}}">
@@ -600,7 +595,7 @@
</c:DragThumb.InputBindings>
</c:DragThumb>
<s:PointContainer x:Name="PART_PointContainer" Style="{StaticResource innerConnectorContainer}" ItemsSource="{Binding Vertices}" Visibility="Collapsed">
<s:PointContainer x:Name="PART_VerticesContainer" Style="{StaticResource innerConnectorContainer}" ItemsSource="{Binding Vertices}" Visibility="Collapsed">
<s:PointContainer.ItemTemplate>
<DataTemplate>
<Grid>
@@ -616,7 +611,24 @@
</Style>
</s:PointContainer.Resources>
</s:PointContainer>
<s:PointContainer x:Name="PART_LabelsContainer" Style="{StaticResource innerConnectorContainer}" ItemsSource="{Binding Labels}" >
<s:PointContainer.ItemTemplate>
<DataTemplate>
<Grid s:SelectionProps.EnabledForSelection="True" Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}">
<c:PointDragThumb Cursor="SizeAll" Opacity="0"/>
<s:TextControl Margin="5" />
</Grid>
</DataTemplate>
</s:PointContainer.ItemTemplate>
<s:PointContainer.Resources>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Canvas.Left" Value="{Binding Left}" />
<Setter Property="Canvas.Top" Value="{Binding Top}" />
</Style>
</s:PointContainer.Resources>
</s:PointContainer>
<Rectangle Fill="#7F243859" Opacity="0.5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding ShouldInsertAnchor, Converter={StaticResource BooleanToVisibilityConverter}}">
<i:Interaction.Behaviors>
<s:ControlMouseLeftButtonDownCommandBehavior Command="{Binding AddVertexCommand}" />
@@ -635,7 +647,7 @@
<Setter TargetName="rightarrow"
Property="Fill"
Value="Black" />
<Setter TargetName="PART_PointContainer"
<Setter TargetName="PART_VerticesContainer"
Property="Visibility"
Value="Visible"/>
</DataTrigger>
@@ -651,14 +663,14 @@
<Setter TargetName="rightarrow"
Property="Fill"
Value="Black" />
<Setter TargetName="PART_PointContainer"
<Setter TargetName="PART_VerticesContainer"
Property="Visibility"
Value="Visible"/>
</DataTrigger>
<DataTrigger Value="True"
Binding="{Binding ShouldInsertAnchor}">
<Setter TargetName="PART_PointContainer"
<Setter TargetName="PART_VerticesContainer"
Property="Visibility"
Value="Visible"/>
</DataTrigger>

View File

@@ -18,14 +18,14 @@ namespace AIStudio.Wpf.DiagramDesigner
/// </summary>
public partial class TextControl : UserControl
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"DoubleEdit", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(
public static readonly DependencyProperty DoubleEditProperty = DependencyProperty.Register(
nameof(DoubleEdit), typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(
true));
public bool DoubleEdit
{
get => (bool)GetValue(TextProperty);
set => SetValue(TextProperty, value);
get => (bool)GetValue(DoubleEditProperty);
set => SetValue(DoubleEditProperty, value);
}
public TextControl()
@@ -48,7 +48,10 @@ namespace AIStudio.Wpf.DiagramDesigner
PART_ShowText.SelectionStart = PART_ShowText.Text.Length;
}
(this.DataContext as SelectableDesignerItemViewModelBase).PropertyChanged += TextControl_PropertyChanged;
if (this.DataContext is ISelectable selectable)
{
selectable.PropertyChanged += TextControl_PropertyChanged;
}
TextControl_PropertyChanged(this.DataContext, new System.ComponentModel.PropertyChangedEventArgs("IsSelected"));
}
@@ -56,9 +59,9 @@ namespace AIStudio.Wpf.DiagramDesigner
{
if (e.PropertyName == "IsSelected")
{
if (sender is SelectableDesignerItemViewModelBase itemViewModelBase)
if (sender is ISelectable selectable)
{
if (itemViewModelBase.IsSelected == false)
if (selectable.IsSelected == false)
{
PART_ShowText.Visibility = Visibility.Collapsed;
PART_TextBlock.Visibility = Visibility.Visible;