2009-10-08 7 views
3

Je voudrais remplacer le comportement de RoutedUICommand "Copy" d'un TextBox WPF.Comment remplacer la commande Copier dans la zone de texte WPF?

Est-il possible sans créer une nouvelle classe TextBoxExtended qui hérite de TextBox?

J'ai atteint ce point, mais maintenant je suis un peu perdu.

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 

Avez-vous une idée de la façon de continuer?

Répondre

4

Vous pouvez ajouter une commande de liaison à la zone de texte pour gérer la commande "Copier". Par exemple, comme ceci:

<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> 
Questions connexes