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

Switch -> EventToCommand: Detect if Toggled from user interaction or from webservices/websocket sync

$
0
0

Hello,
first of all, sorry for my english

I have a page with a number of Switch..each switch turn on/off a remote light using webservices.
To make this I used behaviors and Command in ViewModel linked to Toggled event (we call it SetOnOffSwitchCommand)

At page appearing I call a command to load the real state of each switch (we call it OnAppearingCommand),
In this command I call a w.s. and I set on or off each Switch using a IsToggled binded property
Each time I set on or off a Switch, my 'SetOnOffSwitchCommand' is called, and this is not good.
To fix this problem I add in 'SetOnOffSwitchCommand' a way to exit the command without calling the ws:
if (isBusy) then return;
In fact in my OnAppearingCommand I have a 'IsBusy' boolean used to show an ActivityIndicator.

The problem is that I use websocket too, to update the switch status while the user has the page opened.
If a websocket specific message is received, I call a third command in my viewmodel (SetOnOffFromWebServicesCommand)
The problem is that, also using the 'IsBusy' trick, when I change the state of a Switch, the SetOnOffSwitchCommand is called, and the IsBusy flag is set to false form the SetOnOffFromWebServicesCommand before the SetOnOffSwitchCommand is called.

Exist a sure way to fix my problem?
Thanks!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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