How to override Copy command in WPF text box?

I would like to override the behavior of the RoutedUICommand "Copy" WPF text field.

Is this possible without creating a new TextBoxExtended class that inherits from TextBox?

I got to this, but now I'm a little lost.

Private Sub tbSource_PreviewExecuted(ByVal sender As System.Object, ByVal e As System.Windows.Input.ExecutedRoutedEventArgs)

        Dim commandName = DirectCast(e.Command, Input.RoutedUICommand).Text

        If commandName = "Copy" Then

        End If

End Sub

Do you have an idea how to proceed?

+3
source share
1 answer

You can add a command binding to a text field to process the Copy command. For example, for example:

<StackPanel>
  <TextBlock x:Name="TextBox">
    <TextBlock.CommandBindings>
        <CommandBinding Command="{x:Static ApplicationCommands.Copy}"
                        Executed="CommandBinding_Executed"/>
    </TextBlock.CommandBindings>
  </TextBlock>
  <Button Content="Copy" 
          Command="{x:Static ApplicationCommands.Copy}"
          CommandTarget="{Binding ElementName=TextBox}"/>
</StackPanel>
+4
source

Source: https://habr.com/ru/post/1719624/


All Articles