我想覆盖WPF TextBox的RoutedUICommand“Copy”的行为。
是否可以不创建从TextBox继承的新TextBoxExtended类?
我已达到这一点,但现在我有点失落。
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
你知道如何继续吗?
答案 0 :(得分:4)
您可以向文本框添加命令绑定以处理“复制”命令。例如,像这样:
<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>