I want to make some custom views, which inherit from each other, and each take some content.
I am relatively new to Maui and tried to implement 2 basic views like this:
MyGenericView.xaml:
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestMauiApp.MyGenericView">
<ContentView.ControlTemplate>
<ControlTemplate>
<Frame BackgroundColor="Red" Padding="5">
<ContentPresenter />
</Frame>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>
MyMoreSpecificView.xaml:
<local:MyGenericView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestMauiApp.MyMoreSpecificView"
xmlns:local="clr-namespace:TestMauiApp">
<ContentView>
<ContentView.ControlTemplate>
<ControlTemplate>
<Frame BackgroundColor="Blue"
Padding="5">
<ContentPresenter />
</Frame>
</ControlTemplate>
</ContentView.ControlTemplate>
</ContentView>
</local:MyGenericView>
and display them like this:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestMauiApp.MainPage"
xmlns:local="clr-namespace:TestMauiApp">
<StackLayout Spacing="5">
<local:MyGenericView>
<Label Text="Label inside MyGenericView" />
</local:MyGenericView>
<local:MyMoreSpecificView />
<local:MyMoreSpecificView>
<Label Text="Label inside MyMoreSpecificView" />
</local:MyMoreSpecificView>
</StackLayout>
</ContentPage>
Which looks like that:
Which makes sense, since the whole content of the specific view gets overwritten by the Label.
My next attempt was to change MyMoreSpecificView.xaml to this:
<local:MyGenericView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TestMauiApp.MyMoreSpecificView"
xmlns:local="clr-namespace:TestMauiApp">
<ContentView.ControlTemplate>
<ControlTemplate>
<Frame BackgroundColor="Blue"
Padding="5">
<ContentPresenter />
</Frame>
</ControlTemplate>
</ContentView.ControlTemplate>
</local:MyGenericView>
Which results in this:
Which also makes since, as now the content of the generic view get overwritten by the specific view.
What I want is to get a result where the Label is displayed inside the blue frame, which then is inside the red frame.
These attempts above just are the two that made the most sense to me, I tried many other combinations of nested ControlTemplates, ContentViews and ContentPresenters but sadly didn't succeed yet. I feel like creating custom views in Maui is unnecessary complicated in comparison to Android.

