From e2753b0bff44f7a3d13bd9d0d6539f5669bce2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Sun, 12 Mar 2023 15:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E9=94=AE=E6=8B=96=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/MainWindow.xaml.cs | 1 - ...iagramDesigner.Demo_c54dij5m_wpftmp.csproj | 338 ++++++++++++++++++ .../Controls/DesignerCanvas.cs | 49 ++- .../Controls/DragThumb.cs | 4 +- .../Controls/ZoomBox.cs | 56 ++- .../UserControls/DiagramControl.xaml | 38 +- .../UserControls/DiagramControl.xaml.cs | 26 +- .../UserControls/TextControl.xaml | 6 +- .../UserControls/TextControl.xaml.cs | 44 +-- .../BaseViewModel/SelectableViewModelBase.cs | 2 +- .../Controls/FlowchartEditor.xaml | 1 - .../Controls/FlowchartEditor.xaml.cs | 10 +- .../AIStudio.Wpf.Mind_ujws0dco_wpftmp.csproj | 256 +++++++++++++ AIStudio.Wpf.Mind/Controls/MindEditor.xaml | 8 +- AIStudio.Wpf.Mind/Controls/MindEditor.xaml.cs | 10 +- .../ViewModels/MindDiagramViewModel.cs | 4 +- 16 files changed, 711 insertions(+), 142 deletions(-) create mode 100644 AIStudio.Wpf.DiagramDesigner.Demo/AIStudio.Wpf.DiagramDesigner.Demo_c54dij5m_wpftmp.csproj create mode 100644 AIStudio.Wpf.Mind/AIStudio.Wpf.Mind_ujws0dco_wpftmp.csproj diff --git a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml.cs b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml.cs index 40ff85c..f69b67c 100644 --- a/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml.cs +++ b/AIStudio.Wpf.DiagramApp/Views/MainWindow.xaml.cs @@ -46,7 +46,6 @@ namespace AIStudio.Wpf.DiagramApp private void HookEvents() { - this.PreviewMouseWheel += this.OnPreviewMouseWheel; } diff --git a/AIStudio.Wpf.DiagramDesigner.Demo/AIStudio.Wpf.DiagramDesigner.Demo_c54dij5m_wpftmp.csproj b/AIStudio.Wpf.DiagramDesigner.Demo/AIStudio.Wpf.DiagramDesigner.Demo_c54dij5m_wpftmp.csproj new file mode 100644 index 0000000..8ea3849 --- /dev/null +++ b/AIStudio.Wpf.DiagramDesigner.Demo/AIStudio.Wpf.DiagramDesigner.Demo_c54dij5m_wpftmp.csproj @@ -0,0 +1,338 @@ + + + AIStudio.Wpf.DiagramDesigner.Demo + obj\Debug\ + obj\ + F:\aistudio.-wpf.-diagram\AIStudio.Wpf.DiagramDesigner.Demo\obj\ + <_TargetAssemblyProjectName>AIStudio.Wpf.DiagramDesigner.Demo + + + + WinExe + true + + + + + + + + + + + + + + + + + + Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index 677cd24..ce70b2d 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -188,10 +188,16 @@ namespace AIStudio.Wpf.DiagramDesigner public DesignerCanvas() { - this.AllowDrop = true; + this.Focusable = true; Mediator.Instance.Register(this); _service.PropertyChanged += _service_PropertyChanged; + this.Loaded += DesignerCanvas_Loaded; + } + + private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e) + { + this.Focus(); } protected override void OnRender(DrawingContext dc) @@ -322,9 +328,12 @@ namespace AIStudio.Wpf.DiagramDesigner protected override void OnMouseDown(MouseButtonEventArgs e) { - base.OnMouseDown(e); + base.OnMouseDown(e); + if (_viewModel.IsReadOnly) return; + this.Focus(); + if (_service.DrawModeViewModel.CursorMode == CursorMode.Format) { var element = (e.OriginalSource as FrameworkElement); @@ -356,7 +365,7 @@ namespace AIStudio.Wpf.DiagramDesigner _viewModel.ClearSelectedItemsCommand.Execute(null); } - e.Handled = true; + //e.Handled = true; if (_service.DrawModeViewModel.GetDrawMode() == DrawMode.ConnectingLineSmooth) { @@ -435,7 +444,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } } - e.Handled = true; + //e.Handled = true; } protected override void OnMouseUp(MouseButtonEventArgs e) @@ -499,7 +508,33 @@ namespace AIStudio.Wpf.DiagramDesigner sourceConnectorInfo = null; _service.DrawModeViewModel.ResetDrawMode(); - } + } + + protected override void OnPreviewKeyDown(KeyEventArgs e) + { + base.OnPreviewKeyDown(e); + + if (_viewModel.IsReadOnly) return; + + e.Handled = _viewModel.ExecuteShortcut(e); + } + + protected override void OnPreviewMouseWheel(MouseWheelEventArgs e) + { + base.OnPreviewMouseWheel(e); + + if (Keyboard.IsKeyDown(Key.LeftCtrl) == false + && Keyboard.IsKeyDown(Key.RightCtrl) == false) + { + return; + } + + var newZoomValue = _viewModel.ZoomValue + (e.Delta > 0 ? 0.1 : -0.1); + + _viewModel.ZoomValue = Math.Max(Math.Min(newZoomValue, _viewModel.MaximumZoomValue), _viewModel.MinimumZoomValue); + + e.Handled = true; + } protected override Size MeasureOverride(Size constraint) { @@ -555,7 +590,7 @@ namespace AIStudio.Wpf.DiagramDesigner { base.OnDrop(e); - if (_viewModel.IsReadOnly) return; + if (_viewModel.IsReadOnly) return; DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject; if (dragObject != null) @@ -620,7 +655,7 @@ namespace AIStudio.Wpf.DiagramDesigner _viewModel.AddItemCommand.Execute(itemBase); } } - e.Handled = true; + e.Handled = true; } public FullyCreatedConnectorInfo FindNearPortToAttachTo() diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs index 32db98b..fcf7e1d 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DragThumb.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Windows; -using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; @@ -23,6 +21,8 @@ namespace AIStudio.Wpf.DiagramDesigner.Controls private bool drag; private void DragThumb_DragStarted(object sender, DragStartedEventArgs e) { + GetDesignerCanvas(this)?.Focus(); + drag = false; SelectableDesignerItemViewModelBase designerItem = this.DataContext as SelectableDesignerItemViewModelBase; diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/ZoomBox.cs b/AIStudio.Wpf.DiagramDesigner/Controls/ZoomBox.cs index 32788f5..a804d17 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/ZoomBox.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/ZoomBox.cs @@ -5,6 +5,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Windows.Input; using AIStudio.Wpf.DiagramDesigner.Helpers; +using System.Diagnostics; namespace AIStudio.Wpf.DiagramDesigner { @@ -67,17 +68,20 @@ namespace AIStudio.Wpf.DiagramDesigner { if (oldDesignerCanvas != null) { - oldDesignerCanvas.LayoutUpdated -= new EventHandler(this.DesignerCanvas_LayoutUpdated); - oldDesignerCanvas.MouseWheel -= new MouseWheelEventHandler(this.DesignerCanvas_MouseWheel); + oldDesignerCanvas.LayoutUpdated -= this.DesignerCanvas_LayoutUpdated; + oldDesignerCanvas.MouseDown -= this.DesignerCanvas_MouseRightButtonDown; + oldDesignerCanvas.MouseUp -= this.DesignerCanvas_MouseRightButtonUp; + oldDesignerCanvas.MouseMove -= this.DesignerCanvas_MouseMove; } if (newDesignerCanvas != null) { - newDesignerCanvas.LayoutUpdated += new EventHandler(this.DesignerCanvas_LayoutUpdated); - newDesignerCanvas.MouseWheel += new MouseWheelEventHandler(this.DesignerCanvas_MouseWheel); + newDesignerCanvas.LayoutUpdated += this.DesignerCanvas_LayoutUpdated; + newDesignerCanvas.MouseRightButtonDown += this.DesignerCanvas_MouseRightButtonDown; + newDesignerCanvas.MouseRightButtonUp += this.DesignerCanvas_MouseRightButtonUp; + newDesignerCanvas.MouseMove += this.DesignerCanvas_MouseMove; } } - #endregion public static readonly DependencyProperty OffSetProperty = @@ -182,7 +186,6 @@ namespace AIStudio.Wpf.DiagramDesigner private void DesignerCanvas_LayoutUpdated(object sender, EventArgs e) { - //htzk try { @@ -194,22 +197,41 @@ namespace AIStudio.Wpf.DiagramDesigner Canvas.SetTop(this.zoomThumb, yOffset + this.ScrollViewer.VerticalOffset * scale); } catch { } + } + + /// + /// 用于记录鼠标按下的点 + /// + private Point _clickPoint = new Point(0, 0); + + private void DesignerCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e) + { + _clickPoint = e.GetPosition((FrameworkElement)sender); + Debug.WriteLine($"({_clickPoint.X},{_clickPoint.Y})"); + DesignerCanvas.Cursor = Cursors.Hand; } - private void DesignerCanvas_MouseWheel(object sender, EventArgs e) + private void DesignerCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { - if (Keyboard.IsKeyDown(Key.LeftCtrl) == false - && Keyboard.IsKeyDown(Key.RightCtrl) == false) + DesignerCanvas.Cursor = Cursors.Arrow; + } + + private void DesignerCanvas_MouseMove(object sender, MouseEventArgs e) + { + if (e.RightButton == MouseButtonState.Pressed) { - return; + FrameworkElement cabSender = (FrameworkElement)sender; + //_clickPoint=new Point(scroll.ActualWidth/2,scroll.ActualHeight/2); + double x; + double y; + Point p = e.MouseDevice.GetPosition(cabSender); + + x = _clickPoint.X - p.X; + y = _clickPoint.Y - p.Y; + + ScrollViewer?.ScrollToHorizontalOffset(ScrollViewer.HorizontalOffset + x); + ScrollViewer?.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + y); } - - MouseWheelEventArgs wheel = (MouseWheelEventArgs)e; - - //divide the value by 10 so that it is more smooth - double value = Math.Max(0, wheel.Delta / 10); - value = Math.Min(wheel.Delta, 10); - this.zoomSlider.Value += value; } private void InvalidateScale(out double scale, out double xOffset, out double yOffset) diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml index 6f71932..b492a67 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml @@ -309,7 +309,7 @@ + Value="{Binding ItemHeight}" /> @@ -842,18 +842,18 @@ + ItemContainerStyleSelector="{x:Static dd:DesignerItemsControlItemStyleSelector.Instance}"> + Height="{Binding PageSize.Height}" + Width="{Binding PageSize.Width}" + ShowGrid="{Binding ShowGrid}" + GridCellSize="{Binding GridCellSize}" + GridMarginSize="{Binding GridMarginSize}" + GridColor="{Binding GridColor}" + Background="{Binding PageBackground,Converter={StaticResource ColorBrushConverter}}" + AllowDrop="{Binding AllowDrop}"> @@ -876,18 +876,18 @@ HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> + ItemContainerStyleSelector="{x:Static dd:DesignerItemsControlItemStyleSelector.Instance}"> + Height="{Binding PageSize.Height}" + Width="{Binding PageSize.Width}" + ShowGrid="{Binding ShowGrid}" + GridCellSize="{Binding GridCellSize}" + GridMarginSize="{Binding GridMarginSize}" + GridColor="{Binding GridColor}" + Background="{Binding PageBackground,Converter={StaticResource ColorBrushConverter}}" + AllowDrop="{Binding AllowDrop}"> diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml.cs b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml.cs index 244d7bc..dd1f55c 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml.cs +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/DiagramControl.xaml.cs @@ -27,8 +27,6 @@ namespace AIStudio.Wpf.DiagramDesigner { this.Resources.MergedDictionaries.Add(ResourceDictionary); } - - this.Focusable = true; } public static readonly DependencyProperty ResourceDictionaryProperty = DependencyProperty.Register(nameof(ResourceDictionary), typeof(ResourceDictionary), typeof(DiagramControl), new UIPropertyMetadata(null, OnResourceDictionaryChanged)); @@ -64,28 +62,6 @@ namespace AIStudio.Wpf.DiagramDesigner } } - protected override void OnPreviewKeyDown(KeyEventArgs e) - { - base.OnPreviewKeyDown(e); - - e.Handled = DiagramViewModel.ExecuteShortcut(e); - } - - protected override void OnPreviewMouseWheel(MouseWheelEventArgs e) - { - base.OnPreviewMouseWheel(e); - - if (Keyboard.IsKeyDown(Key.LeftCtrl) == false - && Keyboard.IsKeyDown(Key.RightCtrl) == false) - { - return; - } - - var newZoomValue = DiagramViewModel.ZoomValue + (e.Delta > 0 ? 0.1 : -0.1); - - DiagramViewModel.ZoomValue = Math.Max(Math.Min(newZoomValue, DiagramViewModel.MaximumZoomValue), DiagramViewModel.MinimumZoomValue); - - e.Handled = true; - } + } } diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml index ef0103e..2fc44b0 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml @@ -49,10 +49,10 @@ HorizontalContentAlignment="{Binding FontViewModel.HorizontalAlignment}" VerticalContentAlignment="{Binding FontViewModel.VerticalAlignment}" TextBlock.LineHeight="{Binding FontViewModel.LineHeight}" - AcceptsReturn="True" + AcceptsReturn="True" + Focusable="False" dd:ControlAttachProperty.Watermark="{Binding Path=(dd:ControlAttachProperty.Watermark),RelativeSource={RelativeSource AncestorType={x:Type dd:TextControl}}}" Style="{StaticResource WaterTextBoxWithEffect}" Visibility="Collapsed"> - - + diff --git a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs index 6660121..4d41cb2 100644 --- a/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs +++ b/AIStudio.Wpf.DiagramDesigner/UserControls/TextControl.xaml.cs @@ -18,15 +18,6 @@ namespace AIStudio.Wpf.DiagramDesigner /// public partial class TextControl : UserControl { - //public static readonly DependencyProperty DoubleEditProperty = DependencyProperty.Register( - // nameof(DoubleEdit), typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata( - // true)); - - //public bool DoubleEdit - //{ - // get => (bool)GetValue(DoubleEditProperty); - // set => SetValue(DoubleEditProperty, value); - //} public TextControl() { @@ -62,6 +53,7 @@ namespace AIStudio.Wpf.DiagramDesigner if (this.DataContext is ISelectable selectable) { selectable.IsEditing = PART_ShowText.IsVisible; + PART_ShowText.Focusable = PART_ShowText.IsVisible; } } @@ -89,39 +81,7 @@ namespace AIStudio.Wpf.DiagramDesigner PART_ShowText.SelectionStart = PART_ShowText.Text.Length; } } - } - - //protected override void OnPreviewMouseDown(MouseButtonEventArgs e) - //{ - // base.OnPreviewMouseDown(e); - - // if (DoubleEdit == false) - // { - // PART_ShowText.Visibility = Visibility.Visible; - // PART_TextBlock.Visibility = Visibility.Collapsed; - // PART_ShowText.Focus(); - // if (!string.IsNullOrEmpty(PART_ShowText.Text)) - // { - // PART_ShowText.SelectionStart = PART_ShowText.Text.Length; - // } - // } - //} - - //protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e) - //{ - // base.OnPreviewMouseDoubleClick(e); - - // if (DoubleEdit == true) - // { - // PART_ShowText.Visibility = Visibility.Visible; - // PART_TextBlock.Visibility = Visibility.Collapsed; - // PART_ShowText.Focus(); - // if (!string.IsNullOrEmpty(PART_ShowText.Text)) - // { - // PART_ShowText.SelectionStart = PART_ShowText.Text.Length; - // } - // } - //} + } } public class ControlAttachProperty diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs index 9a3d507..ba5d57c 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/SelectableViewModelBase.cs @@ -166,7 +166,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private bool _isEditing = true; + private bool _isEditing = false; public bool IsEditing { get diff --git a/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml b/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml index c5da1b6..cc9500b 100644 --- a/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml +++ b/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml @@ -8,7 +8,6 @@