【发布时间】:2020-03-13 17:17:38
【问题描述】:
当用户点击主页上的 btnOffline 时,它会将他们重定向到第二页。当用户单击第二页上的按钮完成(button_clicked 事件)时,我将记录时间戳。我现在面临的错误是当它在 button_clicked 事件之后导航回主页时,我再次单击 btnOffline 和 btnDone,lblEndDT 的时间戳发生了变化。我只想从第二页获得第一次点击,但它仍然会发生变化
主页
public partial class MainPage : ContentPage
{
public string mainpagevalue;
int offlinecount = 0;
int onlinecount = 0;
public MainPage()
{
InitializeComponent();
}
private void btnOffline_Clicked(object sender, EventArgs e)
{
offlinecount++;
txtOfflineStatus.Text = "IN PROGRESS";
Navigation.PushAsync(new SecondPage(this, lblEndDT, txtOfflineStatus, btnOnline, btnMH));
if (offlinecount == 1)
{
string currentDT = DateTime.Now.ToString();
lblStartDT.Text = currentDT;
}
}
第二页
public partial class SecondPage : ContentPage
{
Label MainPagelblEndDT;
MainPage mainPage;
ImageButton myImageBtn;
int btndonecount = 0;
public SecondPage()
{
InitializeComponent();
}
public SecondPage(MainPage mainP,Label lblEndDT)
{
InitializeComponent();
//Get the lblEndDT reference here
MainPagelblEndDT = lblEndDT;
//Get the MainPage reference here
mainPage = mainP;
}
public SecondPage(MainPage mainP, Label lblEndDT, ImageButton imageBtn)
{
InitializeComponent();
//Get the lblEndDT reference here
MainPagelblEndDT = lblEndDT;
//Get the MainPage reference here
mainPage = mainP;
//Get the ImageButton reference here
myImageBtn = imageBtn;
}
private void Button_Clicked(object sender, EventArgs e)
{
btndonecount++;
if(btndonecount == 1)
{
string edt = DateTime.Now.ToString();
MainPagelblEndDT = edt;
mainPage.mainpagevalue = MainPagelblEndDT.Text;
}
Navigation.PopAsync();
}
}
【问题讨论】:
-
我试过了,还是变了
标签: c# xaml xamarin xamarin.forms