2016-10-06 6 views
0

xamarinポータブルプロジェクト(iOSおよびAndriod)の全ページにわたるユーザーのログイン詳細を表示するにはどうすればよいですか。 ASP.netやSilverlightのフレームでやっているように私はMasterPageコンセプトを実装することができません。 私はすでにMasterDetailPageを使いましたが、私の要求を満たしていないと思います。xamarinポータブルフォームの全ページにわたるログイン詳細

+0

すべてのページのナビゲーションバーにログインの詳細を表示しますか?それとも何か? –

+0

ナビゲーションバーはきれいです –

+0

ログインページでは、ログインの詳細を静的なクラスに保存し、詳細ページのコンテンツページに 'Title = SomeStaticClass.LoginId'というタイトルを表示することができます –

答えて

2

App.csファイルに静的変数UserNameを作成します。 LoginPage.csファイルで

public class App : Application 
{ 
    public static bool IsUserLoggedIn { get; set; } 
    public static string UserName { get; set; } 

    public App() 
    { 
     if (!IsUserLoggedIn) 
     { 
      MainPage = new NavigationPage(new LoginPage()); 
     } 
     else 
     { 
      MainPage = new NavigationPage(new MenuPage()); 
     } 
    } 
} 

、とき初めてユーザログインApp.csファイルの静的変数にユーザ名を格納します。私はあなたがログインボタンと一緒にユーザー名とパスワードフィールドのような2つの入力フィールドを持つログインページを持っていると仮定しています。あなたはMenuPageにリダイレクトする可能性が成功したログイン認証で

App.UserName = usernameEntry.Text.ToString(); 

:だから、ログインボタンのときに、ユーザーがクリックすると、入力フィールドからユーザ名を格納します。同様に、あなたのポータブルプロジェクトの任意のページにまたがって、この静的変数にアクセスすることができ

public partial class MenuPage : MasterDetailPage 
    { 
     public MenuPage() 
     { 
      InitializeComponent(); 

      string name = App.UserName; 

     } 
    } 

:あなたは簡単としてApp.csファイルの静的変数にアクセスすることができますMenuPage.csファイルで

。この静的変数は、Androidのデバイスの現在実行中のアプリケーショントレイリストからアプリを削除しない限り保持されます。マスター詳細ページの

サンプル・プロジェクト:

https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation

ログインフローのサンプル・プロジェクト:ログイン時に

https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/LoginFlow

0

ここでは、あなたがやりたいものです引き出しのヘッダーに表示するイメージと名前を取得し、定数に格納します。ここにあなたのdrawerpage.xaml.csで

あなたの引き出しページはこちら

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MasterDetailsPageLogin.Views.DrawerPage" 
      Title="Menu" 
      BackgroundColor="#8999A6" 
      Padding="0,20,0,0"> 
    <StackLayout Orientation="Vertical"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="10"/> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="10"/> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
     <RowDefinition Height="30"/> 
     <RowDefinition Height="80"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="5"/> 
     </Grid.RowDefinitions> 
     <BoxView Grid.ColumnSpan="3" 
       Grid.RowSpan="4" 
       BackgroundColor="#8999A6"/> 
     <Image 
      x:Name="img" 
      Grid.Column="1" 
      Grid.Row="1" 
      HorizontalOptions="Start" 
      VerticalOptions="End" 
      WidthRequest="75" HeightRequest="75"/> 
     <Label 
      x:Name="myName" 
      Grid.Column="1" 
      Grid.Row="2"/> 
    </Grid> 
    <ListView x:Name="listed" SeparatorColor="Transparent"> 
    </ListView> 
    </StackLayout> 
</ContentPage> 

コード

public DrawerPage() 
     { 
      InitializeComponent(); 
      string howILook = Constants.Image; 

      img.Source = new UriImageSource 
      { 
       Uri = new Uri(howILook), 
       CachingEnabled = true, 
       CacheValidity = new TimeSpan(1, 0, 0, 0) //Caching image for a day 
      }; 

      myName.Text = "Welcome Mr. " + Constants.Username; 
     } 

は、私は、ログインロジックとマスター詳細ページ用に作成したテンプレートです。 https://github.com/ak47akshaykulkarni/MasterDetailsPageLogin

関連する問題