Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Create ToolbarItems using template or some other dynamic mechanism.

$
0
0

Hi guys,

I have few common toolbar items which I want to add on every view of the application.
(Though there are some specific items per view, however let's not worry about them right now.)

What I want is to add these common toolbar items via a template or external file/code in XF - PCL.

I tried the following code which gets compiled without error, however crashes, I am not sure how I can overcome this issue.

MainPage.xaml: (Note the xmlns:mnu)

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mnu="clr-namespace:Toolbarz.Views;assembly=Toolbarz"
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             x:Class="Toolbarz.Views.MainPage"
             Title="MainPage">
    <mnu:ToolBarMenu></mnu:ToolBarMenu> <!--THIS GETS COMPILED HOWEVER DOES NOT WORK-->
    <!--
         THIS CODE WORKS
         <ContentPage.ToolbarItems>
             <ToolbarItem Text="Help" Priority="0" Order="Secondary"/>
             <ToolbarItem Text="License" Priority="0" Order="Secondary"/>
             <ToolbarItem Text="About" Priority="0" Order="Secondary"/>
         </ContentPage.ToolbarItems>-->
    <ContentPage.Content>
    <StackLayout HorizontalOptions="Center" VerticalOptions="Center">
        ....
    </StackLayout>
    </ContentPage.Content>
</ContentPage>

ToolBarMenu.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Toolbarz.Views.ToolBarMenu">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Help" Priority="0" Order="Secondary"/>
        <ToolbarItem Text="License" Priority="0" Order="Secondary"/>
        <ToolbarItem Text="About" Priority="0" Order="Secondary"/>
    </ContentPage.ToolbarItems>
</ContentView>

Can you suggest what's wrong with this approach?
OR
Could you please suggest any solution which will help me use the ToolbarItems using some template?

Thanks.
N Baua


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>