简体   繁体   中英

MVVMLight's EventToCommand in Xamarin.Forms

I have Xamarin.Forms project portable - 4 sub-projects: PCL along with iOS, WP and Droid.

I would like to use Interaction.Triggers (from System.Windows.Interactivity - from Blend SDK to be exact) and EventToCommand (from MVVM Light) in my PCL project (shared UI for every platform). Is it possible?

I know that MVVM Light is portable, but System.Windows.Interactivity is not, so I have huge problem. How can I use EventToCommand in Xamarin.Forms?

In your Xamarin project :

Right click "References", "Add References". In Assemblies -> Extensions there is System.Windows.Interactivity which can be checked and added.

This is all it takes :)

I did it in such way:

First I added namespace to my page

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:b="clr-namespace:Xamarin.Behaviors;assembly=Xamarin.Behaviors">

Then I added behavior to my ContentPage

<b:Interaction.Behaviors>
  <b:BehaviorCollection>
    <b:EventToCommand EventName="Appearing" Command="{Binding InitializeViewModelCommand}" />
  </b:BehaviorCollection>
</b:Interaction.Behaviors>

Hope it will help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM