Xamarin Forms Switch Toggled event doesn't bind with viewmodel

前端 未结 4 1010
抹茶落季
抹茶落季 2021-01-12 02:45

I have a Forms XAML Page and in there I have a listview, and each element has a Switch (xamarin default). I can bind the data from the items to the listview, but I cannot su

4条回答
  •  借酒劲吻你
    2021-01-12 03:01

    Solution : After doing some R&D i found the root cause of this issue,

    Error Code in very first post:

    
    

    Just do Two steps.

    1. Declare event listener function OnToggled in ContentPage class and not into your ViewModel class that you need to bind

    In your ContentPage class

    void OnToggled(object sender, ToggledEventArgs e){
    
    }
    
    1. change Toggled="{Binding Toggled}" == to ==> Toggled="OnToggled"

    it will fix the issue, Don't know why it don't work for event listener function declared in ViweModel class.

    --I hope it will work.

提交回复
热议问题