简体   繁体   English

如何将数据从Navigation.PopAsync传递到上一页?

[英]How do you pass data from Navigation.PopAsync to previous page?

I have seen other questions regarding passing data between navigation pages but I can't seem to pass an int from Page2 to Page1. 我还看到了有关在导航页面之间传递数据的其他问题,但似乎无法将int从Page2传递给Page1。

I have Page1 that pushes another Pushes Page2, when a button is clicked on Page2 I Pop the content page and need to pass an integer to Page1. 我有Page1可以推另一个Pushs Page2,当在Page2上单击一个按钮时,我弹出内容页面,并且需要将整数传递给Page1。

Does anyone have any ideas? 有人有什么想法吗?

I saw a video on Events and Delegates and got it running! 我看了有关活动和代表的视频 ,并开始播放!

Page1: 第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);
    }
}

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PopAsync将数据传递到上一页? - How to pass data to the previous page using PopAsync? Navigation.PopAsync暂时显示旧页面 - Navigation.PopAsync showing the old page for a moment Monotouch interactivePopGestureRecognizer和Navigation.popasync()空白视图 - Monotouch interactivePopGestureRecognizer and Navigation.popasync() blank view Xamarin/Tizen:执行 Navigation.PopAsync() 使应用程序崩溃 - Xamarin/Tizen: Executing Navigation.PopAsync() crashes the app Navigation.PopAsync() 在用于离开应用程序时不起作用 - Navigation.PopAsync() don't work when being used to leave the application 无法从内容页面执行 PopAsync、PopModalAsync 和 PopToRootAsync - Not able to do PopAsync, PopModalAsync and PopToRootAsync from the content page 如何使用ASP.NET MVC 3将“昂贵”的数据从页面传递到页面? - How do you pass “expensive” data from page to page using ASP.NET MVC 3? 使用导航->转到报告时,如何将数据源传递到本地报告? - How do you pass data source to a local report when you use Navigation-> Go to report? Xamarin.Forms.Navigation.PopAsync()不会弹出页面 - Xamarin.Forms.Navigation.PopAsync() Does Not Pop Page 如何从另一个页面传递数据? - How do I pass data from another page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM