我已经看到了有关在导航页面之间传递数据的其他问题,但我似乎无法将Page2从Page2传递给Page1。
我有Page1推送另一个推送Page2,当在Page2上点击按钮时,我弹出内容页面并需要将整数传递给Page1。
有没有人有任何想法?
答案 0 :(得分:2)
第1页:
public partial class Page1 : ContentPage, INotifyPropertyChanged
{
public static int _player;
public static int Player
{
get{ return _player; }
set{ _player = value; }
}
public NewGameH(string homeTeam, string opponentTeam)
{
InitializeComponent();
}
public void OnPlayerSet(object source, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("Begin Player {0} ", Player);
}
async void button1_Clicked(object sender, System.EventArgs e)
{
var page2 = new Page2();
page2.PlayerSet += this.OnPlayerSet;
await Navigation.PushAsync(page2);
}
}
2页:
public partial class Page2 : ContentPage{
public delegate void SetPlayerEventHandler(object source, EventArgs args);
public event SetPlayerEventHandler PlayerSet;
public Page2()
{
InitializeComponent();
}
protected virtual void OnPlayerSet(){
if (PlayerSet != null){
PlayerSet(this, EventArgs.Empty);
}
}
async void button2_Clicked(object sender, System.EventArgs e)
{
Page1.Player=1;
OnPlayerSet();
await Navigation.PopAsync();
}
}