-1

I'm extending the prism sample here to also include icons, and some additional navigation. My goal is to add something like the code below (where the icon information is) and am unsure how to add that to either my view, or the view model correctly.

<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:WebOfTrust.Views"
             x:Class="WebOfTrust.Views.Client.WebOfTrustMainPage"
             Title="{Binding Title}">
    <TabbedPage.Children>

      <!-- HOW DO I SET AN ICON FOR THESE? Either in the View or Model? --> 
     <NavigationPage Title="Contacts" >
        <x:Arguments> 
            <local:Client.MyPeople.MyPeopleList/>  
        </x:Arguments> 
    </NavigationPage> 

    <NavigationPage Title="Places" Icon="Image7DoesntWork.png">
        <x:Arguments>
             <local:Client.MyPlaces.MyPlacesList/>    
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="Docs" Icon="Image7DoesntWork.png">
        <x:Arguments>
           <local:Client.MyWallet.WalletCards/>  
        </x:Arguments>
    </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

What normally works

I normally have a navigation page in the view where I specify the icon below.

<NavigationPage Title="Trust Anchor List">
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="tab_feed.png"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <local:Client.TrustAnchorList />
            </x:Arguments>
 </NavigationPage>

Question

What is the right way to set an icon in either the view or the model when using Prism?

enter image description here

TLDR
  • 1,198
  • 1
  • 12
  • 31

1 Answers1

0

just add the icon attribute in the children of the tabbed page. It works fine for me

<local:ContactUs Icon="Icons/History_Tab.png" Title="{Translate:TranslateExtension Text=NewMessage}" />

my icons are under a folder in the resources but you can put them anywhere.

Ali123
  • 740
  • 13
  • 38
  • Thanks, I was using TypeArguments, and am so confused about that bit. Do you know what that's about? – TLDR Sep 07 '18 at 15:38
  • Also your usage of translate extension seems interesting.. do you use that for internationalization? – TLDR Sep 07 '18 at 15:39
  • TypeArguments are just parameters that will be passed to the constructor or method that you are calling. It's the XAML way of passing parameters through the UI. TranslateExtension is used for Localization and showing the text dynamically according to the set culture. – Ali123 Sep 08 '18 at 08:11
  • Seems like this won't work when I use another navigation page as updated above – TLDR Oct 01 '18 at 19:08
  • I am not sure why you want to add a Navigation Page as a root to tabbed Page? You can just push the tabbed page if the root page is a navigation page and it will inherit the navigation bar and the back button. – Ali123 Oct 04 '18 at 05:11
  • this is just a normal content page local describes the xmlns:controls="clr-namespace:Namespace_Of_Class;assembly=..." – Ali123 Oct 04 '18 at 05:14