出于某种原因,当尝试通过Stop()方法以编程方式激活按钮时,按钮图像不会更改回与正常状态关联的图像,直到我再次使用鼠标单击按钮。有什么想法吗?
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);
}
答案 0 :(得分:1)
您必须从按钮的主线程发送操作。
public void Stop()
{
buttonStartStop.InvokeOnMainThread (new NSAction (()=> {
buttonStartStop.SendActionForControlEvents(UIControlEvent.TouchUpInside);
}));
}