2017-01-27 6 views
0

私はAndroid開発に慣れていて、簡単な作業であると思うほど難しいです。Xamarinフォーム - 別のXaml内のコンテンツを表示する方法

私は(ContainerView.xamlと呼ばれる)MasterDetailPageを持っています。

マスターはナビゲーションバー(NavbarView.xaml)です。

詳細は、タイトルバーが固定されたページとなり、ユーザーごとにスワップできる「表示」が選択されています。

詳細ページはMainView.xamlと呼ばれます。

タイトル私はトップに表示したいと思って、TitleBarView.xamlと呼ばれています。

次に、私はPage1View.xamlのようないくつかのコンテンツページを持っています。私ContainerView.xamlで

:私のNavbarView.xamlで

<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"    
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
        x:Class="MyApp.ContainerView" 
        IsGestureEnabled="True" 
        MasterBehavior="Popover" 
        Title="MasterDetail Page"> 
    <MasterDetailPage.Master> 
    </MasterDetailPage.Master> 
    <MasterDetailPage.Detail> 
    </MasterDetailPage.Detail> 
</MasterDetailPage> 

- これが私のMainView.xamlのマスター

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.NavBarView" 
      Title="Nav Bar"> 
    <ContentPage.Content> 
    <StackLayout Orientation="Vertical"> 
     <Label Text="{Binding Item1}"/> 
     <Button Text="Options" Command="{Binding Option1Command}"/> 
    </StackLayout > 
    </ContentPage.Content> 
</ContentPage> 

である - これは詳細

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.MainView" 
      Title="Main View"> 
    <ContentPage.Content> 
    // what to put here to show the TitleBarView.xaml? 
    // what to put here to show my content xaml pages? 
    </ContentPage.Content> 
</ContentPage> 
です

、私のTitleBarView.xaml

<?xml version="1.0" encoding="UTF-8"?> 
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.TitleBarView"> 
    <ContentView.Content>  
    <StackLayout Orientation="Horizontal"> 
     <Label Text="{Binding Item1}"/> 
     <Button Text="Options" Command="{Binding OptionsCommand}"/> 
    </StackLayout>  
    </ContentView.Content> 
</ContentView> 

と、一般的なコンテンツビュー、もちろんそこに私はMVVMモデルを使用しています

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.Page1View"> 
    <ContentView.Content> 
    <StackLayout Orientation="Vertical"> 
     <Label Text="{Binding Info}"/> 
     <Button Text="Log In" Command="{Binding GoToPage2Command}"/> 
    </StackLayout > 
    </ContentView.Content> 
</ContentView> 

切り替えると、このコードを持つようにしたい多くの人になりますが、ちょうどように見えることはできません基本的な作業。 マスターページが正常に表示されます。 詳細ページが単なるページであれば動作しますが、タイトルバーを挿入して「コンテンツ」をスワップする方法はわかりません。

ContainerView containerPage = new ContainerView(); 
ContainerViewModel containerVM = new ContainerViewModel(); 
containerPage.BindingContext = containerVM; 

NavBarView navigationBar = new NavBarView(); 
navigationBar.Title = "Navigation Bar"; // required, otherwise I get an exception. 
NavBarViewModel navigationBarVM = new NavBarViewModel(); 
navigationBar.BindingContext = navigationBarVM; 

MainView mainView = new MainView(); 
mainView.Title = "MainView"; 
MainViewModel mainViewVM = new MainViewModel(); 
mainView.BindingContext = mainViewVM; 

TitleBarView titleBar = new TitleBarView(); 
TitleBarViewModel titleBarVM = new TitleBarViewModel(); 
titleBar.BindingContext = titleBarVM; 

Page1View page1 = new Page1View(); 
Page1ViewModel page1VM = new Page1ViewModel(); 
page1.BindingContext = page1VM; 

mainView.Content = new StackLayout() 
{ 
    Orientation = StackOrientation.Vertical, 
    Children = 
    { 
     new Label { Text = "I'm Content!" }, 
     new Label { Text = "I'm Content!" }, 
     //titleBar.Content, 
     //loginView.Content 
    } 
}; 

containerPage.MasterBehavior = MasterBehavior.Popover; 
containerPage.Master = navigationBar; 
containerPage.Detail = new NavigationPage(mainView); 

私は基本的な概念が欠けていると確信しています。すべてのヘルプは、XAMLはTitleBarViewの場合には、あなたが

<xmlnsprefix:TitleBarView /> 

ことによって、任意のXAMLでそれをinsatiateことができますので、問題が権利を設定することで、コードまたはXAMLで定義され、任意のコントロールをインスタンス化することができます

答えて

1

いただければ幸いですxmlnsprefix。すべてのXAMLファイル数のxmlnsを定義し、このように、自分自身を追加することができます。

xmlns:local="clr-namespace:MyApp" 

、それは「ローカル」のXML名前空間は、CLR名前空間を参照すること「MyAppの」現在のアセンブリを意味するだろう。

ですから、MAINVIEWが

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:MyApp" 
    x:Class="MyApp.MainView" 
    Title="Main View"> 
    <ContentPage.Content> 
    <local:TitleBarView /> 
    </ContentPage.Content> 
</ContentPage> 
なり
関連する問題