I wanted to do the same as this question, but for .NET MAUI: Same header & footer in all WPF windows
It is same header and footer for all windows.
I wanted to do the same as this question, but for .NET MAUI: Same header & footer in all WPF windows
It is same header and footer for all windows.
I found a better way to do it using control templates.
PageLayout.xaml file:
<ContentPage ...>
<ContentPage.Resources>
<ControlTemplate x:Key="PageLayoutTemplate">
<Grid RowDefinitions="Auto,*,Auto">
<!--Header-->
<Grid>
<!--header content-->
</Grid>
<!--Content-->
<ContentPresenter Grid.Row="1"/>
<!--Footer-->
<Grid Grid.Row="2">
<!--footer content-->
</Grid>
</Grid>
</ControlTemplate>
</ContentPage.Resources>
</ContentPage>
SubView.xaml file:
<PageLayout ...
ControlTemplate="{StaticResource PageLayoutTemplate"}>
<Grid>
<!--Main content-->
</Grid>
</PageLayout>
Why this is better:
Reference: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/controltemplate?view=net-maui-7.0
If you don't want to click the link @Jason provided in the comment, here is a shortened version.
PageLayout.xaml file:
<ContentPage ...>
<Grid RowDefinitions="Auto,*,Auto">
<!--Row 1 : Header-->
<Grid>
<!--header content-->
</Grid>
<!--Row 2 : Content-->
<Grid Grid.Row="1"
Name="PrimaryPageLayout">
</Grid>
<!--Row 3 : Footer-->
<Grid Grid.Row="2">
<!--footer content-->
</Grid>
</Grid>
</ContentPage>
PageLayout.xaml.cs file :
public partial class PageLayout : ContentPage
{
public IList<IView> PageLayoutContent => PrimaryPageLayout.Children;
public PageLayout()
{
InitializeComponent();
}
}
SubView.xaml file:
<PageLayout ... >
<views:PageLayout.PageLayoutContent>
<!--Main content-->
</views:PageLayout.PageLayoutContent>
</PageLayout>