Reputation: 305
For some reason, when trying to activate the button programmatically via the Stop() method, the button image does not change back to the image associated with the normal state until I click on the button again with the mouse. Any ideas?
public void Stop()
{
buttonStartStop.SendActionForControlEvents(UIControlEvent.TouchUpInside);
}
partial void actionButtonStartStopPress(MonoTouch.Foundation.NSObject sender)
{
Console.WriteLine("StartStop Button State On Entering Handler: " + buttonStartStop.State);
if(buttonStartStop.State == UIControlState.Highlighted)
{
buttonStartStop.Selected = true;
buttonStartStop.Highlighted = true;
buttonLiveHome.Enabled = false;
buttonLiveBack.Enabled = false;
buttonCalibrate.Enabled = false;
MainLoop.StreamData(true);
}
else
{
buttonStartStop.SetTitle("Start", UIControlState.Normal);
buttonStartStop.Selected = false;
buttonStartStop.Highlighted = false;
buttonLiveHome.Enabled = true;
buttonLiveBack.Enabled = true;
buttonCalibrate.Enabled = true;
MainLoop.StreamData(false);
}
Console.WriteLine("StartStop Button State On Exiting Handler (0 means Normal): " + buttonStartStop.State);
}
Upvotes: 1
Views: 461
Reputation: 1341
You must send the action from the main thread for the button.
public void Stop()
{
buttonStartStop.InvokeOnMainThread (new NSAction (()=> {
buttonStartStop.SendActionForControlEvents(UIControlEvent.TouchUpInside);
}));
}
Upvotes: 1