Qu'avez-vous essayé? Ce code fonctionne pour moi:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.CommandBindings>
<CommandBinding Command="Cut" Executed="CommandBinding_Executed" />
</Window.CommandBindings>
<StackPanel>
<TextBox x:Name="textBox1" />
<Button Command="Cut"
CommandParameter="{Binding Text,ElementName=textBox1}"
Content="Cut" />
</StackPanel>
</Window>
Avec ce gestionnaire d'événements:
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(e.Parameter.ToString());
}
Je veux utiliser TextChanged ou lorsque textbox utilisateur clique sur entrée du champ de saisie clavier. Je ne veux pas appuyer sur le bouton. –
Si vous utilisez une commande, vous devez utiliser une ICommandSource comme un bouton. Les commandes ne sont pas identiques aux gestionnaires d'événements. –