3

I would like to override the behavior of RoutedUICommand "Copy" of a WPF TextBox.

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

I have reached that point, but now I am bit 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 any idea how to continue?

Grhm
  • 6,726
  • 4
  • 40
  • 64
Drake
  • 8,225
  • 15
  • 71
  • 104

1 Answers1

4

You can add a command binding to the text box to handle the "Copy" command. For example, like this:

<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>
Pavlo Glazkov
  • 20,498
  • 3
  • 58
  • 71