且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

与MasterDetails页面和导航Xamarin.forms

更新时间:2022-06-19 08:23:13

保存设置之后,你应该改变的细节的已有的的MasterDetailPage实例。

After saving the settings you should change the detail of an exisiting MasterDetailPage instance.

我觉得这样做最简单和最清晰的方法是使用的 MessagingCenter

I think the simplest and clearest way to do this is using MessagingCenter:

在设置页面:

MessagingCenter.Send(new OpenMyPageMessage(), OpenMyPageMessage.Key);

您主从页面:

protected override void OnAppearing()
{
    MessagingCenter.Subscribe<OpenMyPageMessage>(this, OpenMyPageMessage.Key, (sender) =>
        {
            Detail = new YourAnotherPage();
        });
}

protected override void OnDisappearing()
{
    MessagingCenter.Unsubscribe<OpenMyPageMessage>(this, OpenMyPageMessage.Key);
}

OpenMyPageMes​​sage 是只是一个简单的类:

And OpenMyPageMessage is just a simple class:

public class OpenMyPageMessage
{
    public static string Key = "OpenMyPageMessage";
}



结果:
与MasterDetails页面和导航Xamarin.forms