【发布时间】: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