あなたにトリックを与える!ログインページがあるとします。認証後に、masterDetailPageであるRootPageに移動します。
はコード
namespace LoginNavigation
{
public class App : Application, IloginInterface
{
public static App current;
public static bool IsUserLoggedIn { get; set; }
public static double ScreenWidth;
public static double ScreenHeight;
public App() {
current = this;
MainPage = new LoginPageWithStack();
}
public void Logout() {
MainPage = new LoginPageWithStack();
}
public void ShowMainPage() {
MainPage = new RootPage();
}
}
}
rootPage下からからヒントを取る:
namespace LoginNavigation
{
public class RootPage:MasterDetailPage
{
MenuPage menuPage;
public RootPage() {
ToolbarItems.Add(new ToolbarItem("Filter", "ring.png", async() => {
var page = new ContentPage();
var result = await page.DisplayAlert("Title", "Message", "Accept", "Cancel");
Debug.WriteLine("success: {0}", result);
}));
menuPage = new MenuPage();
menuPage.Menu.ItemSelected += (sender, e) => NavigateTo (e.SelectedItem as MenuItemForMaster);
//Master = new MasterMenu();
Master = menuPage;
Detail = new NavigationPage (new TimeSheet()){
BarBackgroundColor = Color.FromHex("008dce"),BackgroundColor = Color.FromHex("008dce")
};
}
void NavigateTo (MenuItemForMaster menu) {
if (menu == null)
return;
Page displayPage = (Page)Activator.CreateInstance (menu.TargetType);
//Detail = displayPage;
Detail = new NavigationPage (displayPage) { BarBackgroundColor = Color.FromHex("008dce"),BackgroundColor = Color.FromHex("008dce")};
menuPage.Menu.SelectedItem = null;
IsPresented = false;
}
}
}
だから、トリックは、Appクラスの現在のインスタンスを取得し、それをメインページプロパティを操作する、です。
私はそれを試しましたが、まだ動作していません。コンテンツページの後でマスター詳細ページに移動できるように、App.csで記述する必要がある特定のコードを更新してください。 – anand