Note that there are some explanatory texts on larger screens.

plurals
  1. POTriggering a command from a textbox when enter is pressed?
    primarykey
    data
    text
    <p>Let me start by saying that I am new to <code>MVVM</code>, so please bare with be, if the question is unclear let me know and I will try to clarify.</p> <p>I have correctly implemented a <code>button</code> in <code>XAML</code> with <code>multibinding</code>, the code is as follows:</p> <pre><code>&lt;Button x:Name="licenceFilterSet" Content="Search License" Command="{Binding licenseSearchCommand}" Click="licenceFilterButtonClick" HorizontalAlignment="Right" Width="94"&gt; &lt;Button.Resources&gt; &lt;local:SearchFilterConverter x:Key="SearchFilterConverter" /&gt; &lt;/Button.Resources&gt; &lt;Button.CommandParameter&gt; &lt;MultiBinding Converter="{StaticResource SearchFilterConverter}"&gt; &lt;Binding Path="Text" ElementName="filterLicenseTextBox" /&gt; &lt;Binding Path="IsChecked" ElementName="regularExpressionCheckBox" /&gt; &lt;/MultiBinding&gt; &lt;/Button.CommandParameter&gt; &lt;/Button&gt; </code></pre> <p>(the value of a textbox and a checkbox is sent to be proceed).</p> <p>Now I would like to add the exact same feature to the textBox, where the user can directly press <code>ENTER</code> in the <code>textBox</code> and perform the same operation.</p> <p>I tried the following code, but it seems that each character is now sent to the command, but I only want the command to be sent when the user presses <code>ENTER</code>. What should I change?</p> <pre><code>&lt;TextBox Name="filterLicenseTextBox"&gt; &lt;TextBox.Resources&gt; &lt;local:SearchFilterConverter x:Key="SearchFilterConverter" /&gt; &lt;/TextBox.Resources&gt; &lt;TextBox.Text&gt; &lt;MultiBinding Converter="{StaticResource SearchFilterConverter}"&gt; &lt;Binding Path="Text" ElementName="filterLicenseTextBox" Mode="OneWay"/&gt; &lt;Binding Path="IsChecked" ElementName="regularExpressionCheckBox" Mode="OneWay"/&gt; &lt;/MultiBinding&gt; &lt;/TextBox.Text&gt; &lt;TextBox.InputBindings&gt; &lt;KeyBinding Key="Enter" Command="{Binding licenseSearchCommand}"&gt; &lt;/KeyBinding&gt; &lt;/TextBox.InputBindings&gt; &lt;/TextBox&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload