title: Xamarin Forms EventToCommandBehavior
body: <p>I have been trying to follow the example for EventToCommandBehavior located at: </p>
  
  <p><a href="https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/behaviors/reusable/event-to-command-behavior/" rel="nofollow noreferrer">https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/behaviors/reusable/event-to-command-behavior/</a></p>
  
  <p>The example shows a selectedItem event being fired for an item in a list view. My hope is to fire a Switch event for any item in my list view.</p>
  
  <p>I did make sure to change the EventName from "ItemsSelected" To "Toggled" (the event for the switch) but the event isn't hit at all. What could I be doing wrong?</p>
  
  <p>FWIW, I'm trying to follow the MVVM pattern and minimize "code behind"</p>
  
  <p>GaragePage.xaml</p>
  
  <pre><code>  &lt;ContentPage.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;converters:ToggledItemEventArgsConverter x:Key="ToggledConverter" /&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/ContentPage.Resources&gt;
  
                    &lt;ListView x:Name="listView" VerticalOptions="StartAndExpand" HasUnevenRows="true" ItemsSource="{Binding Previews}" HeightRequest="800" SeparatorVisibility="None"
                                      behaviors:ListViewBehavior.NoBackgroundSelection="True"&gt;
                              &lt;ListView.ItemTemplate&gt;
                                  &lt;DataTemplate&gt;
                                      &lt;ViewCell&gt;
                                          &lt;cardView:CardView Margin="40,15,40,15" HeightRequest="200"  CardViewOutlineColor="{StaticResource Primary}" Padding="5" CardViewOutlineColorThickness="1" CardViewHasShadow="True"&gt;
                                              &lt;cardView:CardView.CardViewContent&gt;
                                                  &lt;StackLayout Orientation="Vertical"  BackgroundColor="White" &gt;
                                                      &lt;StackLayout VerticalOptions="CenterAndExpand" &gt;
                                                          &lt;StackLayout Grid.Row="0" Grid.Column="0"  &gt;
                                                              &lt;StackLayout   HorizontalOptions="Center"&gt;
                                                                  &lt;Label Text="Enable Mobile Alert" FontSize="Small" TextColor="{StaticResource LightTextColor}"/&gt;
                                                                  &lt;Switch IsToggled="{Binding PushNotification}" HorizontalOptions="Center"&gt;
                                                                      &lt;Switch.Behaviors&gt;
                                                                          &lt;behaviors:EventToCommandBehavior EventName="Toggled" Command="{Binding ToggleAlertCommand}" Converter="{StaticResource ToggledConverter}" /&gt;
                                                                      &lt;/Switch.Behaviors&gt;
                                                                  &lt;/Switch&gt;
                                                              &lt;/StackLayout&gt;
                                                          &lt;/StackLayout&gt;
                                                      &lt;/StackLayout&gt;
                                                  &lt;/StackLayout&gt;
                                              &lt;/cardView:CardView.CardViewContent&gt;
                                          &lt;/cardView:CardView&gt;
                                      &lt;/ViewCell&gt;
                                  &lt;/DataTemplate&gt;
                              &lt;/ListView.ItemTemplate&gt;
                          &lt;/ListView&gt;
  </code></pre>
  
  <p>GaragePageViewModel.cs</p>
  
  <pre><code>public ICommand ToggleAlertCommand { get; private set; }
  
  public GaragePageViewModel()
      {
          ToggleAlertCommand = new Command&lt;Vehicle&gt;(ToggleMobileAlert);
      }
  
  private async Task ToggleMobileAlert(GarageVehicle vehicle)
      {
         //do work
      }
  </code></pre>
  
  <p>ToggledItemEventArgsConverter.cs</p>
  
  <pre><code>public class ToggledItemEventArgsConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          var eventArgs = value as ToggledEventArgs;
          return eventArgs.Value;
      }
  
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>GaragePage.xaml.cs</p>
  
  <pre><code>   public GaragePage()
          {
              InitializeComponent();
              BindingContext = App.Container.Resolve&lt;GaragePageViewModel&gt;();
          }
  </code></pre>