Duplicate ToolbarItems code in every page

Hi,
I am creating ToolbarItems in Xamarin.Forms. To show ToolbarItems in every page, I am using same code across all pages. How can I reduce code?
See

MainPage.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="ToolbarXam.MainPage">
    <ContentPage.ToolbarItems>
        <ToolbarItem Name="MenuItem1" Order="Primary" Text="Item 1" Priority="0" />
        <ToolbarItem Name="MenuItem2" Order="Primary" Text="Item 2" Priority="1" />
    </ContentPage.ToolbarItems>

    <StackLayout VerticalOptions="Center">
        <Button Text="Go to page2" Margin="10" Clicked="btnNextPage_Clicked"></Button>
    </StackLayout>
</ContentPage>

The same code I am using in other pages otherwise Toolbar not displaying. Thank you

Posts

Sign In or Register to comment.