Hello,
Welcome to our Microsoft Q&A platform!
Is it possible if we just create it once and apply it to all pages?
You can create a parent contentpage(e.g. CustomContentPage
) and let the other pages inherit it.
You can refer to the following code:
CustomContentPage.xaml.cs
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CustomContentPage : ContentPage
{
public CustomContentPage()
{
InitializeComponent();
}
}
CustomContentPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TabbedPageWithNavigationPage.CustomContentPage">
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal">
<Image Source="star.png"
WidthRequest="40"
HeightRequest="40"
VerticalOptions="CenterAndExpand"
/>
<Label Text="test page" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
<Image Source="gallary.png"
WidthRequest="40" HeightRequest="40"
VerticalOptions="CenterAndExpand"
/>
</StackLayout>
</NavigationPage.TitleView>
</ContentPage>
Make other pages inherit it, for example there is a SettingsPage
page, we can do like this:
public partial class SettingsPage : CustomContentPage
{
public SettingsPage ()
{
InitializeComponent ();
}
}
and SettingsPage.xaml
:
<?xml version="1.0" encoding="UTF-8"?>
<tabbedpagewithnavigationpage:CustomContentPage xmlns:tabbedpagewithnavigationpage="clr-namespace:TabbedPageWithNavigationPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TabbedPageWithNavigationPage.SettingsPage" IconImageSource="settings.png" Title="Settings">
<ContentPage.Content>
<StackLayout>
<Label Text="Settings go here" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>
</tabbedpagewithnavigationpage:CustomContentPage>
Now the UI of page SettingsPage
is:
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.