如何在Platform标记上的ToolbarItem上绑定图像图标

问题描述 投票:0回答:2

如何在Xamarin.Forms中的ToolbarItem OnPlatform标记上绑定图像图标

这是我的代码:

<ToolbarItem 
    Icon="{OnPlatform iOS='iconscalendarplus64.png', Android='iconscalendarplus64.png'}" 
    Priority="0"
    Order="Primary" 
    Command="{Binding PrikaziCommand}"

我正在尝试为Android OnPlatform绑定图像,但是它不起作用。

xamarin.forms android-toolbar
2个回答
0
投票

最简单的方法是:

                <ToolbarItem.Icon>
                <OnPlatform x:TypeArguments="ImageSource">
                    <OnPlatform.iOS><FileImageSource File=""icon.png""/></OnPlatform.iOS>
                    <OnPlatform.Android><FileImageSource File=""icon.png""/></OnPlatform.Android>
                    <OnPlatform.WinPhone><FileImageSource File=""Images/icon.png""/></OnPlatform.WinPhone>
                </OnPlatform>
                </ToolbarItem.Icon>

好是您可以在这里基于平台使用所有四种类型的ImageSource。

祝您好运,如有疑问,请随时回来


0
投票

由于AndroidAndroidiOS属性不是OnPlatform

它们不支持数据绑定。因此,您不能绑定那些属性。

作为替代,您可以将平台特定的图像源设置为ViewModel中的一个属性,而您可以将其设置为。

XAML

BindableProperty

查看模型

BindableProperty

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.