How do I update my label text in main page, on button click event at another content page?
Example: When user click on image button, I will update the current time stamp in lblStartDT
. The image button will redirect the user to another page, and when the user click "done" button, I want to update my lblEndDT
with the current time stamp back at the main page. I don't know how to call the label from one page to another.
(P.S this is my first time using xamarin forms so I am not sure what approach I can use)
<Label Text="Start Date Time:" Grid.Row="1" Grid.Column="3"/>
<Label Text="End Date Time:" Grid.Row="1" Grid.Column="3" Margin="7,40,0,0"/>
<Label x:Name="lblStartDT" Text="-" Grid.Column="4" Grid.Row="1"/>
<Label x:Name="lblEndDT" Text="-" Grid.Column="4" Grid.Row="1" />
MainPage code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Test
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class workorderpage : ContentPage
{
public workorderpage()
{
InitializeComponent();
}
private void btnOffline_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new OfflineToolPage());
txtStatus.Text = "IN PROGRESS";
string currentDT = DateTime.Now.ToString();
lblStartDT.Text = currentDT;
}
}
Second Page
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Test
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class OfflineToolPage : ContentPage
{
public OfflineToolPage()
{
InitializeComponent();
}
private void btnDone_Clicked(object sender, EventArgs e)
{
#I want to call the label here
}
}