2017-09-06 6 views
1

私はうまくいかないXamarin.Formsを使って奇妙な動作が発生しています。Xamarin.Formsタブ付きページとログアウト

アプリの基本的な流れは、ランディングページがログインフォームであることです。ログインすると、タブ付きページに移動します。ログアウト機能を使用すると、ログインページに戻りますが、タブはそのまま残ります。

Login.xaml

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="TechsportiseApp.Login"> 
    <ContentPage.Padding> 
     <OnPlatform x:TypeArguments="Thickness" 
        iOS="20, 40, 20, 20" 
        Android="20, 20, 20, 20" 
        WinPhone="20, 20, 20, 20" /> 
    </ContentPage.Padding> 
    <ContentPage.Content> 
     <StackLayout VerticalOptions="FillAndExpand" 
        HorizontalOptions="FillAndExpand" 
        Orientation="Vertical" 
        Spacing="15"> 
      <Label Text="Email" /> 
      <Entry x:Name="email" Text="[email protected]" /> 
      <Label Text="Password" /> 
      <Entry x:Name="password" Text="xxxxxx" IsPassword="true"/> 
      <Button x:Name="loginButton" Text="Login" Clicked="OnLogin"/> 
      <Button x:Name="registerButton" Text="Register Account" Clicked="OnRegister"/> 
      <Button x:Name="clearButton" Text="Reset" Clicked="OnClear"/> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

私はログインのためのAPIから成功コードを取得した場合は、このセクションでは、メインページに移動します。

Login.xaml.cs

//Valid response 
       if (response.StatusCode.ToString() == "OK") 
       { 
        Application.Current.Properties["Token"] = tokenobject.access_token; 
        string token = Application.Current.Properties["Token"].ToString(); 
        Navigation.InsertPageBefore (new MainPage(), this); 
        await Navigation.PopAsync(); 

       } 

MainPage.xamlをは、次のようになりますし、タブ付きのナビゲーションページです。

<?xml version="1.0" encoding="UTF-8"?> 
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:TechsportiseApp.MainUI" 
    x:Class="TechsportiseApp.MainUI.MainPage"> 

    <local:Races /> 
    <local:Timer /> 
    <local:Scanning /> 
    <NavigationPage Title="Settings"> 
     <x:Arguments> 
      <local:Settings /> 
     </x:Arguments> 
    </NavigationPage> 
</TabbedPage> 

各ページにはすべて有効です。設定ページには[ログアウト]ボタンがあります。この

async void OnLogout(object sender, EventArgs e) 
{ 
    Application.Current.Properties["Token"] = ""; 
    Navigation.InsertPageBefore (new Login(), this); 
    await Navigation.PopAsync(); 
} 

をやっSettings.xaml.csでログアウトボタンで

Settings.xaml

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="TechsportiseApp.MainUI.Settings" 
      Title="Settings"> 
    <ContentPage.Content> 
     <StackLayout> 
      <Label Text="Settings will go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" /> 
      <Button x:Name="logoutButton" Text="Logout" Clicked="OnLogout" VerticalOptions="CenterAndExpand" /> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

しかし、最終結果は、私はログイン画面を持っているということです。.. 。下のタブバーで

enter image description here

どうしたのですか?ログアウトするとタブが表示されないようにしたいと思います。

おかげで、新しいメインページの設定 マット

+1

あなたのNavigationPageはあなたのTabbedページ内にあるので、Navigationを使って何かをTabbedページの中に残します。代わりにあなたのアプリのメインページを置き換える必要があります。 – Jason

+0

NavigationPage内でTabbedPageを動かしてみてください。ログアウトしたら、ログインページに移動します。 –

答えて

1

は仕事をしてくれました。ログインとログアウトについて私は、アプリケーションの新しいメインページを、

App.Current.MainPage = new NavigationPage(new MainPage()) 

PopAsync/PushAsyncの代わりに設定しました。

関連する問題