Hi,
I am using MVVM pattern and i have a textbox in parent window and want to send some text to the popup window which will appear on Textchanged.
I tried using commandparameter but it is not working for me.
Please help..
Thanks Sharath
Hi,
I am using MVVM pattern and i have a textbox in parent window and want to send some text to the popup window which will appear on Textchanged.
I tried using commandparameter but it is not working for me.
Please help..
Thanks Sharath
What have you tried? This code works for 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>
With this event handler:
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show(e.Parameter.ToString());
}
If i want the command to be executed if the user presses enter, i like to use this. Note the clever use of the IsDefault Binding :-)
<TextBox x:Name="inputBox"/>
<Button Command="{Binding CutCommand}"
CommandParameter="{Binding Text, ElementName=inputBox}"
Content="Cut"
IsDefault="{Binding IsFocused, ElementName=inputBox}" />
If you don't want the button to be visible, you can set its visibility to collapsed of course. I think it'll still execute the command if you hit enter.