This project is read-only.


StyleMVVM provides the class DelegateCommand which is a default implementation of the ICommand interface. Below is an example of how to wire up a button handler.

    <Button Command="{Binding ClickCommand}">Click Me</Button>

    private DelegateCommand clickCommand;

    public DelegateCommand ClickCommand
           if(clickCommand == null)
               clickCommand = new DelegateCommand(clickHandler);

           return clickCommand;

    private void clickHandler(object parameter)


While Commands are nice you will need to handle more events than just Click. To that end StyleMVVM offers a simple way to use public methods from your ViewModel to handle events. Below is an example of how to hook up the ItemClick and SelectionChanged events on a GridView control.

XAML - short hand
    <GridView IsItemClickEnabled="True"
         View:EventHandlers.Attach="ItemClick => ItemClickHandler($sender,$eventArgs); SelectionChanged => SelectionChangedHandler($dataContext);" />

XAML - long hand
    <GridView IsItemClickEnabled="True">
                  <View:EventHandlerInstance Attach="ItemClick => ItemClickHandler($sender,$eventArgs);"/>
                  <View:EventHandlerInstance Attach="SelectionChanged => SelectionChangedHandler($dataContext);"/>

    public void ItemClickHandler(FrameworkElement sender, ItemClickEventArgs clickEventArgs)


    public void SelectionChangedHandler(object dataContext)


Last edited Oct 16, 2013 at 9:45 PM by ipjohnson123, version 6


No comments yet.