using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace AIStudio.Wpf.DiagramDesigner { /// /// Interaction logic for DiagramControl.xaml /// public partial class DiagramControl : UserControl { public DiagramControl() { InitializeComponent(); if (ResourceDictionary != null) { 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)); private static void OnResourceDictionaryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is DiagramControl diagram) { if (e.NewValue is ResourceDictionary dictionary) { diagram.Resources.MergedDictionaries.Add(dictionary); } } } public ResourceDictionary ResourceDictionary { get { return (ResourceDictionary)GetValue(ResourceDictionaryProperty); } set { SetValue(ResourceDictionaryProperty, value); } } public static readonly DependencyProperty ZoomValueProperty = DependencyProperty.Register(nameof(ZoomValue), typeof(double), typeof(DiagramControl), new UIPropertyMetadata(1d)); public double ZoomValue { get { return (double)GetValue(ZoomValueProperty); } set { SetValue(ZoomValueProperty, value); } } private void DesignerCanvas_Loaded(object sender, RoutedEventArgs e) { //DesignerCanvas myDesignerCanvas = sender as DesignerCanvas; //zoomBox.DesignerCanvas = myDesignerCanvas; } private async void ScaleTransform_Changed(object sender, EventArgs e) { await System.Threading.Tasks.Task.Delay(100); ZoomValue = scale.ScaleX; } private IDiagramViewModel DiagramViewModel { get { return DataContext as IDiagramViewModel; } } protected override void OnPreviewKeyDown(KeyEventArgs e) { base.OnPreviewKeyDown(e); if (DiagramViewModel.DiagramOption.ShortcutOption.SelectAll(e)) { DiagramViewModel.SelectAllCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Copy(e)) { DiagramViewModel.CopyCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Paste(e)) { DiagramViewModel.PasteCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Cut(e)) { DiagramViewModel.CutCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Undo(e)) { DiagramViewModel.UndoCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Redo(e)) { DiagramViewModel.RedoCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Delete(e)) { DiagramViewModel.DeleteCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.LeftMove(e)) { DiagramViewModel.LeftMoveCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.RightMove(e)) { DiagramViewModel.RightMoveCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.UpMove(e)) { DiagramViewModel.UpMoveCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.DownMove(e)) { DiagramViewModel.DownMoveCommand.Execute(null); e.Handled = true; return; } else if (DiagramViewModel.DiagramOption.ShortcutOption.Group(e)) { DiagramViewModel.GroupCommand.Execute(null); e.Handled = true; return; } } } }