I am new to C# Maui and stuck on a simple task where I could not find any information how to do it.
My goal is to create a XAML-Template, which I then can fill with other XAML-Content.
My Idea is to have something like this as a new template
<HorizontalStackLayout x:Class="MyTemplate">
<Label Text="template header" />
<!--new content here-->
<Label Text="template footer" />
</HorizontalStackLayout>
So afterwards I use it like this:
<MyTemplate>
<Label Text="content" />
</MyTemplate>
Which then should create the same output as:
<HorizontalStackLayout>
<Label Text="template header" />
<Label Text="content" />
<Label Text="template footer" />
</HorizontalStackLayout>
Obivously I do not want to add just a label but as much stuff as I want. In my case I want to use it amongst others to create a template for an pages which all should have the same stuff above and below.
I tried it like this:
<?xml version="1.0" encoding="utf-8" ?>
<mct:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
x:Class="Page.EntryPopup">
<ContentView>
<ContentView.ControlTemplate>
<ControlTemplate>
<VerticalStackLayout>
<Label
Text="Header"
VerticalOptions="Center"
HorizontalOptions="Center" />
<ContentPresenter />
<Label
Text="Footer"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>
</mct:Popup>
And afterwards:
<page:EntryPopup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mct="clr-namespace:CommunityToolkit.Maui.Views;assembly=CommunityToolkit.Maui"
xmlns:page="clr-namespace:View.Page"
x:Class="Page.ActivityPopup">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</page:EntryPopup>
But this showed only "Welcome to .NET MAUI!" but not the header and footer.
You need to sign in to view this answers
Leave feedback about this