public static void SetCommand(KeyboardAccelerator ka, ICommand command) { ka.SetValue(CommandProperty, command); ka.Invoked += (sender, e) => { if (command.CanExecute(GetCommandParameter(ka))) { e.Handled = true; command.Execute(GetCommandParameter(ka)); } }; }
// 计算出放置字幕的位置,设置宽度以表示持续时长 private void AddCaption_Click(object sender, RoutedEventArgs e) { if (inputSubtitle.Text is "") { return; } try { _ = graphGlobal.fileInputNode.Position; } catch { return; } TextBox textBox1 = new TextBox { Name = "subtitleEdit" + subtitle_counter.ToString(), Text = inputSubtitle.Text, PlaceholderText = "请在此输入字幕", CornerRadius = new CornerRadius(4), BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(Color.FromArgb(200, 151, 186, 214)), CanDrag = true, Width = 9 * 5 * 5, IsReadOnly = true, ManipulationMode = ManipulationModes.All }; //textBox1.AddHandler(ManipulationStartingEvent, new ManipulationStartingEventHandler(TextBox1_ManipulationStarting), true); //textBox1.AddHandler(ManipulationStartedEvent, new ManipulationStartedEventHandler(TextBox1_ManipulationStarted), true); //textBox1.AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(TextBox1_ManipulationDelta), true); //textBox1.AddHandler(ManipulationCompletedEvent, new ManipulationCompletedEventHandler(TextBox1_ManipulationCompleted), true); //textBox1.ManipulationStarting += TextBox1_ManipulationStarting; //textBox1.ManipulationStarted += TextBox1_ManipulationStarted; //textBox1.ManipulationDelta += TextBox1_ManipulationDelta; //textBox1.ManipulationCompleted += TextBox1_ManipulationCompleted; textBox1.AddHandler(PointerPressedEvent, new PointerEventHandler(TextBox1_PointerPressed), true); textBox1.AddHandler(PointerMovedEvent, new PointerEventHandler(TextBox1_PointerMoved), true); textBox1.AddHandler(PointerReleasedEvent, new PointerEventHandler(TextBox1_PointerReleased), true); textBox1.PointerEntered += TextBox1_PointerEntered; textBox1.PointerExited += TextBox1_PointerExited; textBox1.PointerPressed += TextBox1_PointerPressed; textBox1.PointerMoved += TextBox1_PointerMoved; textBox1.PointerReleased += TextBox1_PointerReleased; textBox1.TextChanged += TextBox1_TextChanged; var textBoxPixelPosition = graphGlobal.fileInputNode.Position.TotalMilliseconds / 200.0 * 9; //Canvas.SetZIndex(textBox1, 0); Canvas.SetLeft(textBox1, textBoxPixelPosition); subtitlesCanvas.Children.Add(textBox1); TextBox textBox2 = new TextBox { Name = "subtitleText" + subtitle_counter.ToString(), Text = inputSubtitle.Text, PlaceholderText = "请在此输入字幕", CornerRadius = new CornerRadius(2), BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(Color.FromArgb(200, 151, 186, 214)), Margin = new Thickness(5, 5, 0, 0), }; var accelerator = new KeyboardAccelerator() { Modifiers = Windows.System.VirtualKeyModifiers.Shift, Key = Windows.System.VirtualKey.Enter, }; accelerator.SetValue(TextBoxProperty, textBox2); accelerator.Invoked += Accelerator_Invoked; textBox2.KeyboardAccelerators.Add(accelerator); Button deleteButton = new Button { Name = "deleteButton" + subtitle_counter.ToString(), Content = new SymbolIcon(Symbol.Delete), BorderThickness = new Thickness(0), Margin = new Thickness(5, 5, 0, 0), HorizontalAlignment = HorizontalAlignment.Right }; deleteButton.Click += DeleteButton_Click; StackPanel subtitleCrudPanel = new StackPanel { Name = "sutitleCrudPanel" + subtitle_counter.ToString(), Orientation = Orientation.Vertical, HorizontalAlignment = HorizontalAlignment.Right, Width = 300, }; subtitleCrudPanel.Children.Add(textBox2); subtitleCrudPanel.Children.Add(deleteButton); var subtitleHeadTimeNode = new TimeSpan(0, 0, 0, 0, (int)graphGlobal.fileInputNode.Position.TotalMilliseconds); TextBox textStartTime = new TextBox { Name = "textStartTime" + subtitle_counter.ToString(), Text = subtitleHeadTimeNode.ToString(@"mm\:ss\.ff"), CornerRadius = new CornerRadius(2), BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(Color.FromArgb(200, 151, 186, 214)), VerticalContentAlignment = VerticalAlignment.Center, FontSize = 11, Margin = new Thickness(0, 5, 0, 0) }; var subtitleRearTimeNode = new TimeSpan(0, 0, 0, 0, (int)(subtitleHeadTimeNode.TotalMilliseconds + (textBox1.Width / 9) * 200)); TextBox textEndTime = new TextBox { Name = "textEndTime" + subtitle_counter.ToString(), Text = subtitleRearTimeNode.ToString(@"mm\:ss\.ff"), CornerRadius = new CornerRadius(2), BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(Color.FromArgb(200, 151, 186, 214)), VerticalContentAlignment = VerticalAlignment.Center, FontSize = 11, Margin = new Thickness(0, 5, 0, 0) }; StackPanel timeNodeStackPanel = new StackPanel { Name = "timeNodeStackPanel" + subtitle_counter.ToString(), Orientation = Orientation.Vertical, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, 5) }; timeNodeStackPanel.Children.Add(textStartTime); timeNodeStackPanel.Children.Add(textEndTime); StackPanel stackPanel1 = new StackPanel { Name = "rowSubtitlePanel" + subtitle_counter.ToString(), Orientation = Orientation.Horizontal, HorizontalAlignment = HorizontalAlignment.Left, Width = 400, }; stackPanel1.Children.Add(timeNodeStackPanel); stackPanel1.Children.Add(subtitleCrudPanel); appendSubtitles.Children.Add(stackPanel1); lyrics.Add(new Lyric(inputSubtitle.Text, subtitle_counter, subtitleHeadTimeNode, subtitleRearTimeNode)); subtitle_counter++; if (isCaptionExist.Visibility != Visibility.Collapsed) { isCaptionExist.Visibility = Visibility.Collapsed; } inputSubtitle.Text = ""; scrollViewSubtitles.ScrollToVerticalOffset(scrollViewSubtitles.ScrollableHeight); }
public static void SetCommandParameter(KeyboardAccelerator ka, object parameter) => ka.SetValue(CommandParameterProperty, parameter);