【问题标题】:Xamarin Forms button event not firing on AndroidXamarin Forms 按钮事件未在 Android 上触发
【发布时间】:2017-07-11 09:25:34
【问题描述】:

我有一个 Xamarin Forms 应用程序,在我的一个页面中我有两个按钮,在 Android 上,当您点击该按钮时它不会触发事件,它只是突出显示该按钮,如果您再次点击它会触发事件,在 iOS 上它运行完美。以下是一些代码摘录,对不起,如果我的代码有不好的做法,我是菜鸟,所以请纠正我,最好的学习方式:

//初始化页面

public GameDetailsNew(Game myEvent)
    {
        InitializeComponent();
        MyEvent.Text = myEvent.EventName;
        MyTimeHeader.Text = myEvent.TimeOfEvent;
        myEventID = myEvent.EventID;
        Task.Run(() => { GetAttendingEvent(myEvent.EventID); });
    }

//GetAttendingEvent

private void GetAttendingEvent(int eventID)
    {
        var registerLable = "";
        var attendinIsVisible = false;
        var notAttendingIsVisible = false;
        try
        {
            HelperFiles.APICaller ac = new HelperFiles.APICaller();
            var x = (string)ac.CallCOFMOBILEBool("GetIsAttending?eventID=" + eventID);
            if (x == "Attending")
            {
                registerLable = "You are currently Attending this Event";
                attendinIsVisible = false;
                notAttendingIsVisible = true;
            }
            else
            {
                registerLable = "You are currently NOT Attending this Event";
                attendinIsVisible = true;
                notAttendingIsVisible = false;
            }
            Device.BeginInvokeOnMainThread(() =>
                {
                    RegisterLable.Text = registerLable;
                    AttendingButton.IsVisible = attendinIsVisible;
                    NotAttendingButton.IsVisible = notAttendingIsVisible;
                });
        }
        catch (Exception ex)
        {
            MyAlerts("Error", ex.Message, "OK");
        }
    }

//我的到按钮事件处理程序

//Sets User as attending event
    void AttendingClicked(object sender, System.EventArgs e)
    {
        try
        {
            HelperFiles.APICaller ac = new HelperFiles.APICaller();
            var x = (string)ac.CallCOFMOBILEBool("GetCreateAttending?eventID=" + myEventID);
            if (x == "1")
            {
                RegisterLable.Text = "You are currently Attending this Event";
                AttendingButton.IsVisible = false;
                NotAttendingButton.IsVisible = true;
            }
            else
            {
                RegisterLable.Text = "You are currently NOT Attending this Event";
                AttendingButton.IsVisible = true;
                NotAttendingButton.IsVisible = false;
            }
            GetDeployingEvent(myEventID);

        }
        catch (Exception ex)
        {
            MyAlerts("Error", ex.Message, "OK");
        }

    }

    //Sets User as Not attending event
    void NotAttendingClicked(object sender, System.EventArgs e)
    {
        try
        {
            HelperFiles.APICaller ac = new HelperFiles.APICaller();
            var x = (string)ac.CallCOFMOBILEBool("GetCreateNotAttending?eventID=" + myEventID);
            if (x != "1")
            {
                RegisterLable.Text = "You are currently Attending this Event";
                AttendingButton.IsVisible = false;
                NotAttendingButton.IsVisible = true;
            }
            else
            {
                RegisterLable.Text = "You are currently NOT Attending this Event";
                AttendingButton.IsVisible = true;
                NotAttendingButton.IsVisible = false;
            }
            GetDeployingEvent(myEventID);

        }
        catch (Exception ex)
        {
            MyAlerts("Error", ex.Message, "OK");
        }
    }

【问题讨论】:

  • 能否分享一个可以重现问题的基本演示?

标签: xamarin xamarin.android xamarin.forms


【解决方案1】:

我只是想对此进行更新,我设法解决了这个问题。大约 8 个月前,我在 Xamarin Studio 中开始了我的项目,快进几个月后,Xamarin Studios 更改为 Visual Studio。无论我做了什么,我都无法摆脱这个错误,然后我启动了一个全新的应用程序并将我的所有代码粘贴到新应用程序中。这已经解决了这个错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-28
    • 2014-09-19
    • 2013-05-11
    • 2016-07-30
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    • 2017-01-24
    相关资源
    最近更新 更多