I have the following XAML:
<Switch
IsToggled="{Binding IsChecked}"
IsEnabled="true"
Toggled="MyToggledEventHandler"
VerticalOptions="CenterAndExpand"
HorizontalOptions="EndAndExpand" />
This switch exists as part of a custom listview viewcell template, and the records that supply the listview elements are loaded asynchronously as part of the ContentPage's OnAppearing()
method. The ListView is hidden until these records have been loaded, as part of some MultiTriggers I have setup on the ListView to determine its IsVisible
property. When the records get set into the BindableProperty
to feed the listview, MyToggledEventHandler
gets called for each record where IsChecked
is true. This is not desirable because I have a server-side HTTP call that takes place as part of that event handler. How can I avoid this event being thrown while still taking advantage of XAML-only binding?
I should point out that I am not programmatically changing the IsChecked
property at any point - it is true/false at the point that it gets set into the ListView ItemsSource
property.
EDIT:
At the moment I am able to get around this with a secondary "checked" property in the record that is not a BindableProperty
- when it doesn't match the bound property, then I know it was hand-toggled; when they do match, it's on init. I can use that trick to return early from MyToggledEventHandler
. Definitely a hack, but it'll work until I get a better response.