mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
block
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
|
||||
@@ -12,6 +13,16 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
public class DragThumb : Thumb
|
||||
{
|
||||
public static readonly DependencyProperty EditClickCountProperty = DependencyProperty.Register(
|
||||
nameof(EditClickCount), typeof(int), typeof(DragThumb), new FrameworkPropertyMetadata(
|
||||
2));
|
||||
|
||||
public int EditClickCount
|
||||
{
|
||||
get => (int)GetValue(EditClickCountProperty);
|
||||
set => SetValue(EditClickCountProperty, value);
|
||||
}
|
||||
|
||||
public DragThumb()
|
||||
{
|
||||
base.DragDelta += new DragDeltaEventHandler(DragThumb_DragDelta);
|
||||
@@ -23,6 +34,15 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
private SelectableDesignerItemViewModelBase DesignerItem
|
||||
{
|
||||
get
|
||||
{
|
||||
return DataContext as SelectableDesignerItemViewModelBase;
|
||||
}
|
||||
}
|
||||
|
||||
private List<SelectableDesignerItemViewModelBase> designerItems;
|
||||
|
||||
private bool drag;
|
||||
@@ -174,6 +194,49 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls
|
||||
}
|
||||
}
|
||||
|
||||
#region
|
||||
|
||||
private Point? firstPoint;
|
||||
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnPreviewMouseLeftButtonDown(e);
|
||||
|
||||
if (EditClickCount == 1)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed && firstPoint == null)
|
||||
{
|
||||
firstPoint = e.GetPosition(this);
|
||||
DesignerItem.PreviewExecuteEdit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnPreviewMouseLeftButtonDown(e);
|
||||
|
||||
if (EditClickCount == 1)
|
||||
{
|
||||
if (firstPoint == e.GetPosition(this))
|
||||
{
|
||||
DesignerItem.EditCommand?.Execute(e.GetPosition(this));
|
||||
firstPoint = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
|
||||
{
|
||||
base.OnPreviewMouseDoubleClick(e);
|
||||
if (EditClickCount == 2)
|
||||
{
|
||||
DesignerItem.EditCommand?.Execute(e.GetPosition(this));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private DesignerCanvas GetDesignerCanvas(DependencyObject element)
|
||||
{
|
||||
while (element != null && !(element is DesignerCanvas))
|
||||
|
||||
@@ -851,12 +851,7 @@
|
||||
</Grid.ContextMenu>
|
||||
|
||||
<!-- PART_DragThumb -->
|
||||
<c:BlockDragThumb x:Name="PART_DragThumb"
|
||||
Cursor="SizeAll" >
|
||||
<c:BlockDragThumb.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding EditCommand}" CommandParameter="{Binding }" />
|
||||
</c:BlockDragThumb.InputBindings>
|
||||
</c:BlockDragThumb>
|
||||
<c:DragThumb x:Name="PART_DragThumb" EditClickCount="{Binding EditClickCount}" Cursor="Hand" />
|
||||
|
||||
<Grid RenderTransformOrigin="0.5,0.5" >
|
||||
<!-- PART_ContentPresenter -->
|
||||
|
||||
@@ -93,6 +93,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public int EditClickCount
|
||||
{
|
||||
get; set;
|
||||
} = 2;
|
||||
|
||||
private bool enabledForSelection = true;
|
||||
public bool EnabledForSelection
|
||||
{
|
||||
@@ -183,6 +188,12 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public virtual void PreviewExecuteEdit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void ExecuteEditCommand(object param)
|
||||
{
|
||||
if (IsReadOnly == true) return;
|
||||
|
||||
@@ -428,6 +428,11 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
await (this.GetFirst() ?? this).Execute();
|
||||
}
|
||||
|
||||
public override async void PreviewExecuteEdit()
|
||||
{
|
||||
await BeforeExecute();
|
||||
}
|
||||
|
||||
public async Task Execute()
|
||||
{
|
||||
await BeforeExecute();
|
||||
|
||||
Reference in New Issue
Block a user