Français English

MetroEventToCommand 2.0

Finally…the V2.0 is out !

What’s new :

Added :

  • Windows Phone 8 version
  • Very simple test app
  • You can pass event args to the command


Corrected :

  • Memory leak


Here is how to use it :

Get the NuGet package (

Add to your XAML header :


Then, to use it just do like this :

<Button Content="Click Here">
      <metroEventToCommand:EventToCommand Command="{Binding TestCommand}" CommandParameter="{Binding SimpleParam}" Event="Click"></metroEventToCommand:EventToCommand>

Event args

Now you can pass the event args to the command:

To do this, replace the generic type of your command to the new EventParameter<T> type.

The engine will see your command generic parameter is an EventParameter<T>, so it will populate the Sender and Args properties accordingly. If you have a command parameter, it will be set on the Parameter property.

Example :


<Button Content="Click here">
      <metroEventToCommand:EventToCommand Command="{Binding TestCommand}"
            CommandParameter="{Binding TestParameter}"
            Event="Click" />



public Command<EventParameter<int>> TestCommand { get; set; }

public MainPage()

    TestCommand = new Command<EventParameter<int>>((param) =>
        if ((param.Sender is Button) && (param.Parameter == 111))
            //Do something
            //Do something else

    DataContext = this;


Pro and cons

The advantages of my solution :

  • Easy
  • Can use several MetroEventToCommand on the same control for different events
  • Can use full databinding capabilities


The disadvantages :

  • Using a FrameworkElement put some overhead
  • Lot of useless FrameworkElement properties appearing at the Intellisense


Clearly it is not the cleanest solution. But it is an easy one but it works (so far) for the projects I’ve been on.

You can download source and example on Codeplex :

Comments powered by Disqus