Home > Software engineering >  Xamarin Forms IOS Remove IconImageSource
Xamarin Forms IOS Remove IconImageSource

Time:11-25

ToolbarItems with IconImageSource are causing my app to crash on iOS. So I am willing to remove them only on iOS but show the icons on Android. How Can I do that? Thank you!

<TabbedPage.ToolbarItems>
    <ToolbarItem x:Name="searchOptn" IconImageSource="{local:ImageResource Bufib.Logos.search.png}" Clicked="searchOptn_Clicked" />
    <ToolbarItem x:Name="syncOptn" IconImageSource="{local:ImageResource Bufib.Logos.sync.png}" Clicked="syncOptn_Clicked"/>
    <ToolbarItem x:Name="favouriteOptn" Clicked="favouriteOptn_Clicked" Order="Secondary"/>
    <ToolbarItem x:Name="visibilityOptn" Clicked="visibilityOptn_Clicked"  Order="Secondary"/>
</TabbedPage.ToolbarItems>

CodePudding user response:

In Xamarin.Forms, using Device.RuntimePlatform can be used to obtain the mobile phone platform used by the current user.

Judgment and data processing by using the above code.

Here is my background code for your reference:

public partial class TabbedPage1 : TabbedPage
{
    public TabbedPage1()
    {
        InitializeComponent();
    }
    protected override void OnAppearing()
    {
        base.OnAppearing();
        if (Device.RuntimePlatform == "Android")//Determine whether it is Android, if it is, add a picture
        {
            mytest.IconImageSource = "xxx.jpg";
        }
    }
}
  • Related