Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3724506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:39:55+00:00 2026-05-19T06:39:55+00:00

I am using Mvvm-Light Commands to route events from my Views to my ViewModels.

  • 0

I am using Mvvm-Light Commands to route events from my Views to my ViewModels. Works great.

But I think I can be more elegant. This is actually probably just a standard XAML question:

I want to change this (10 buttons all with Click="keypadButton_Click" for their event handler):

<Button  Name="button1" Content="1" Grid.Row="0" Grid.Column="0" Click="keypadButton_Click" />
<Button  Name="button2" Content="2" Grid.Row="0" Grid.Column="1" Click="keypadButton_Click"/>
<Button  Name="button3" Content="3" Grid.Row="0" Grid.Column="2" Click="keypadButton_Click"/>
<Button  Name="button4" Content="4" Grid.Row="1" Grid.Column="0" Click="keypadButton_Click"/>
<Button  Name="button5" Content="5" Grid.Row="1" Grid.Column="1" Click="keypadButton_Click"/>
<Button  Name="button6" Content="6" Grid.Row="1" Grid.Column="2" Click="keypadButton_Click"/>
<Button  Name="button7" Content="7" Grid.Row="2" Grid.Column="0" Click="keypadButton_Click"/>
<Button  Name="button8" Content="8" Grid.Row="2" Grid.Column="1" Click="keypadButton_Click"/>
<Button  Name="button9" Content="9" Grid.Row="2" Grid.Column="2" Click="keypadButton_Click"/>
<Button  Name="button0" Content="0" Grid.Row="3" Grid.Column="1" Click="keypadButton_Click"/>

To 10 of these:

<Button  x:Name="button1" Content="1" Grid.Row="0" Grid.Column="0">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <Command:EventToCommand 
               Command="{Binding KeyPadButtonCommand}"
               CommandParameter="{Binding ElementName=button1, Path=Content }"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</Button>

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:

<Button  Name="button1" Content="1" Grid.Row="0" Grid.Column="0" 
         Click="{Binding _SendTheEventHere_}" />

Where "{Binding _SendTheEventHere_}" should be replaced with some magic incantation that I am clueless about, but I know some wizard here on stackoverflow knows :-).

Make sense?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T06:39:57+00:00Added an answer on May 19, 2026 at 6:39 am

    I’m not sure if I understand you correctly, but you can use RelayCommand in MVVM Light Toolkit here is a sample code

    Generally RelayCommand are implementation of ICommand interface that you can use

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully used a few custom commands using MVVM-Light, but I want my
Using MVVM Light, I have two WPF applications that reference a common Views library.
I am using Mvvm-Light and have been ignoring how binding in XAML really works
I'm using the EventToCommand Class from the MVVM-light-Toolkit to handle the AutoGeneratingColumn-Event in the
I am using MVVM light in conjunction with EF4 and SQL CE 4, but
I am using the MVVM Light framework as well as Unity for DI. I
I'm using MVVM to bind views to objects in a Tree. I have a
I'm using mvvm light to build a Silverlight application. Is there a code snippet
I am using MVVM Light toolkit in my WPF application. I would like to
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.