Che cosa hai provato? Questo codice funziona per me:
<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>
Con questo gestore di eventi:
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(e.Parameter.ToString());
}
fonte
2009-06-19 08:43:34
voglio usare testo TextChanged o quando l'utente fa clic entrano sul testo da tastiera. Non voglio premere. –
Se si sta utilizzando un comando, è necessario utilizzare una risorsa ICommand come un pulsante. I comandi non sono gli stessi di gestori di eventi. –