Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Event To Comand in Xamarin Forms project using .NET Standards


I was wondering if there was an equivalent to the MVVMLight EventToCommand available when using a Xamarin Forms project that's using .NET Standards?

I found the following article: h t t p : / / / turn-events-into-commands-with-behaviors, which basically shows you how to create a ListView behaviour to handle such a requirement but I don't like the idea as I would have to create a behaviour for every control type that require the "EventToCommand".

In the past, I would have used something similar to the below with the Microsoft Interactivity and MVVMLight libraries:



or with arguments



That's just 2 examples but I use this mechanism on many controls such as ListViews, Grids, TreeViews, etc... and while I know many of these won't be used in a Xamarin Forms project, I'd still prefer this scenario over the one where I'd have to create a Behaviour for each control and their corresponding events.

I'd like to know if there is an equivalent in Xamarin forms to this feature or if you know how to use this with the new mvvmlight .net standard library

Many thanks.


  • RCarvalhoRCarvalho PTMember ✭✭

    Were you able to use Service Locator with the new MvvmLight library?

  • Thierry.8340Thierry.8340 USMember ✭✭

    This is a little bit off topic as I was looking for info on how to deal with EventToCommand but here's what I know and did.

    The ServiceLocator is no longer part of the .net Standard MvvmLight Library.

    h t t p :// for more details
    h t t p s://

    I simply created a ViewModelLocator class where I'm defining whatever model I need to access

        static ViewModelLocator()
            // register services
            if (UseMockDataStore)
                SimpleIoc.Default.Register<IDataStore<Item>>(() => new MockDataStore());
                SimpleIoc.Default.Register<IDataStore<Item>>(() => new AzureDataStore());
            if (UseMockDataStore)
                SimpleIoc.Default.Register<IDataService>(() => new MockDataService());
                SimpleIoc.Default.Register<IDataService>(() => new AzureDataService());
            // register view's viewmodels

    and in my app.xaml, I simply declared

            <vm:ViewModelLocator x:Key="Locator" />

    and I can then access any of my ViewModels or I can inject them into my views as normal.

    Hope this helps.

  • Thierry.8340Thierry.8340 USMember ✭✭

    Anyone has any ideas on my EventToCommand question?

    I really would like to know how to best handle this as this is a crucial part of handling a lot various scenarios when using MVVM with specific controls.

    Any help would be greatly appreciated.

  • abraabra ADMember ✭✭✭

    @Thierry.8340 : take a look here

  • Thierry.8340Thierry.8340 USMember ✭✭

    @abra, Thanks for that.

    I've read through the article but don't see anything that mentions EventToCommand equivalent. I'm currently looking at the GitHub repository to see if there is any help/documentation regarding this feature as I don't know Codon.

    Do you know if it supports it? If I find anything, I'll update this post.



  • abraabra ADMember ✭✭✭

    @Thierry: I guess ActionCommand would be the equivalent, did you take a look at it ? Maybe you can find a usage of it in the sample

Sign In or Register to comment.