Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 79144

Binding a switch

$
0
0

Hey guys,

I am trying to SetBinding to a switch in Code - behind (not XAML) but I have not been successful.

homePhoneSwitch.Toggled += (object sender, ToggledEventArgs e) => {
            ViewModel.Settings.HomePhone = e.Value; 
        };

Doing the step above works fine but I have so many switches in my views and this is not an ideal solution.

I have attempted to use SetBinding like this:

        homePhoneSwitch.SetBinding (Switch.IsToggledProperty, new Binding ("Settings.HomePhone"));      
&&                     homePhoneSwitch.SetBinding (Switch.IsToggledProperty, new Binding ("ViewModel.Settings.HomePhone"));
&&          homePhoneSwitch.SetBinding (Switch.IsToggledProperty,  "Settings.HomePhone");

None of the above has worked for me. Is there something I am missing?
This is frustrating as on XAML its fairly straightforward but in the code-behind doesn't seem to work.

Any help is highly appreciated.


Viewing all articles
Browse latest Browse all 79144

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>