What's the best way to display content in a page with a standard layout throughout the application?
I have an app that has a fixed format page layout with a header containing buttons a footer and a bit in the middle that I want to swap out as I navigate around.
<ContentPage>
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Item1}"/>
<Button Text="Options" Command="{Binding ACommand}"/>
<!-- my content here...-->
</StackLayout >
</ContentPage.Content>
</ContentPage>
My options are:
1. Use a ContentTemplate
2. Use views.
3. Cut and paste outer into each new page.
Which is best?
Detail below....
1. Use a ContentTemplate
My xaml would then look like...
<Application.Resources>
<ResourceDictionary>
<!--template theme 1-->
<ControlTemplate x:Key="MyTemplate1">
<StackLayout Orientation="Vertical">
<Label Text="{Binding Item1}"/>
<Button Text="Options" Command="{Binding ACommand}"/>
<ContentPresenter />
</StackLayout >
</ntrolTemplate>
</ResourceDictionary>
</Application.Resources>
and my page....
<ContentPage>
<ContentView x:Name="contentView"
ControlTemplate="{StaticResource MyTemplate1}">
<ContentView.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="0,20,0,0" />
</ContentView.Padding>
<!-- My content here-->
<Grid>
<Label Text = My clever page content" />
<!-- I can put anything in here..... -->
</Grid>
</ContentView>
</ContentPage>
The advantage here is all my pages are logically seperate.
2. Use views.
I define a view for each of my different pages
<ContentView x:Class="MyApp.ContainerView">
<Grid>
<Label Text = My clever page content" />
<!-- I can put anything in here..... -->
</Grid>
</ContentView>
and....
<ContentView x:Class="MyApp.AnotherReallyCleverContentView">
<StackLayout Orientation="Vertical">
<Label Text="Page1's content."/>
</StackLayout >
</ContentView>
and then pages are ...
<ContentPage>
<ContentPage.Content>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Item1}"/>
<Button Text="Options" Command="{Binding ACommand}"/>
<views:ContainerView />
</StackLayout >
</ContentPage.Content>
</ContentPage>
and I can then swap the views out programatically, doing something like....
ContainerPage = new MainPage();
ContainerPage.FindByName<ContentView>("Container").Content = (ContentView)Activator.CreateInstance(AnotherReallyCleverContentView)