1

出于某种原因,当尝试通过 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);
    }
4

1 回答 1

1

您必须从按钮的主线程发送操作。

public void Stop()
{
    buttonStartStop.InvokeOnMainThread (new NSAction (()=> {
        buttonStartStop.SendActionForControlEvents(UIControlEvent.TouchUpInside);
    }));
}
于 2012-05-20T18:49:35.570 回答