Home > Mobile >  How to display image in Xamarin Form ContentPage IconImageSource
How to display image in Xamarin Form ContentPage IconImageSource

Time:10-12

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.

CodePudding user response:

We can use Shell.TitleView as the workaround .

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

enter image description here

Refer to

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

  • Related