Su Ming Yuan
Su Ming Yuan

Reputation: 125

How to display image in Xamarin Form ContentPage IconImageSource

Could anyone advice how to add the image in ContentPage IconImageSource? Trying to display "icon.png" in Title bar. The image from the ToolbarItem, "toolbar_icon.png", is able to display. Both icons are place together in Android Resources drawable folder. Haven't tried for iOS platform yet.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
             x:Class="HelloWorld.Views.AboutPage"
             Title="{Binding Title}"
             IconImageSource="icon.png">
    <ContentPage.ToolbarItems>
        <ToolbarItem IconImageSource="toolbar_icon.png"></ToolbarItem>
    </ContentPage.ToolbarItems>
</ContentPage>

App.xml file is default and doesn't update it.

<Shell xmlns="http://xamarin.com/schemas/2014/forms" 
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       xmlns:local="clr-namespace:HelloWorld.Views"
       Title="HelloWorldApp"
       x:Class="HelloWorldApp.AppShell">
    <TabBar>
        <ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}" />
    </TabBar>
</Shell>

Thanks.

Upvotes: 1

Views: 3000

Answers (2)

ecklerpa
ecklerpa

Reputation: 168

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Notes.Views.ConnectionPage"
             Title="Connection">

    <!-- Add an item to the toolbar -->
    <ContentPage.ToolbarItems>
        <ToolbarItem IconImageSource="/Images/Satellite.ico"  />
    </ContentPage.ToolbarItems>
</ContentPage>

Upvotes: 0

ColeX
ColeX

Reputation: 14463

We can use Shell.TitleView as the workaround .

    <Shell.TitleView>
        <Image Source="icon_feed.png"
           HorizontalOptions="Center"
           VerticalOptions="Center" />
    </Shell.TitleView>

Refer to

https://stackoverflow.com/a/58969359/8187800 .

Upvotes: 2

Related Questions