Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get multiple controls to fire same event/command in Silverlight / XAML?
    primarykey
    data
    text
    <p>I am using Mvvm-Light Commands to route events from my Views to my ViewModels. Works great.</p> <p>But I think I can be more elegant. This is actually probably just a standard XAML question:</p> <p>I want to change this (10 buttons all with <code>Click="keypadButton_Click"</code> for their event handler):</p> <pre><code>&lt;Button Name="button1" Content="1" Grid.Row="0" Grid.Column="0" Click="keypadButton_Click" /&gt; &lt;Button Name="button2" Content="2" Grid.Row="0" Grid.Column="1" Click="keypadButton_Click"/&gt; &lt;Button Name="button3" Content="3" Grid.Row="0" Grid.Column="2" Click="keypadButton_Click"/&gt; &lt;Button Name="button4" Content="4" Grid.Row="1" Grid.Column="0" Click="keypadButton_Click"/&gt; &lt;Button Name="button5" Content="5" Grid.Row="1" Grid.Column="1" Click="keypadButton_Click"/&gt; &lt;Button Name="button6" Content="6" Grid.Row="1" Grid.Column="2" Click="keypadButton_Click"/&gt; &lt;Button Name="button7" Content="7" Grid.Row="2" Grid.Column="0" Click="keypadButton_Click"/&gt; &lt;Button Name="button8" Content="8" Grid.Row="2" Grid.Column="1" Click="keypadButton_Click"/&gt; &lt;Button Name="button9" Content="9" Grid.Row="2" Grid.Column="2" Click="keypadButton_Click"/&gt; &lt;Button Name="button0" Content="0" Grid.Row="3" Grid.Column="1" Click="keypadButton_Click"/&gt; </code></pre> <p>To 10 of these:</p> <pre><code>&lt;Button x:Name="button1" Content="1" Grid.Row="0" Grid.Column="0"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="Click"&gt; &lt;Command:EventToCommand Command="{Binding KeyPadButtonCommand}" CommandParameter="{Binding ElementName=button1, Path=Content }"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/Button&gt; </code></pre> <p>But I don't want that much XAML. I would think there would be a way to "macroize" the Trigger so it would look something like this:</p> <pre><code>&lt;Button Name="button1" Content="1" Grid.Row="0" Grid.Column="0" Click="{Binding _SendTheEventHere_}" /&gt; </code></pre> <p>Where <code>"{Binding _SendTheEventHere_}"</code> should be replaced with some magic incantation that I am clueless about, but I know some wizard here on stackoverflow knows :-).</p> <p>Make sense?</p>
    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