![](/img/trans.png)
[英]ListView Xamarin.forms dynamically load image from ItemSource with ImageResource
[英]Load icons from UWP-library as image in Xamarin.Forms
我有以下情況:
圖書館結構
Base.Library (.Net Standard 2.0 + Xamarin.Forms)
|- Views (XAML)
Base.Library.Android
|- Resources
|- drawables
|- icon.xml
Base.Library.iOS
|- Assets
|- icon (image asset with 3 resolutions)
Base.Library.Upw
|- Icons
|- icon.scale-100.png
|- ...
|- icon.scale-400.png
圖標可以在iOS和Android上正常使用(在ibrary項目的XAML頁面和使用該庫的最終應用程序項目中)。
<Image WidthRequest="24" HeightRequest="24" VerticalOptions="Center"
HorizontalOptions="End">
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="Android,iOS" Value="icon" />
<On Platform="UWP" Value="Icons/icon.png" />
</OnPlatform>
</Image.Source>
</Image>
僅UWP不起作用。 從庫加載圖像是一種特殊的語法嗎?
我已經嘗試了以下方法:
// Prefixed with assembly name of the library
Value="ms-appx:///Base.Library.Uwp/Icons/icon.png"
// Prefixed with namespace of the library
Value="ms-appx:///Base.Library.Uwp.Namespace/Icons/icon.png"
我找到了解決方案。
如果值中包含ms-appx:///
,則將其視為UriImageSource
而不是FileImageSource
。 如果我將其切掉,並使用圖標的完整路徑(包括程序集名稱),則也會顯示UWP的圖標。
<Image WidthRequest="24" HeightRequest="24" VerticalOptions="Center"
HorizontalOptions="End">
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="Android,iOS" Value="icon" />
<!-- Icon name prefixed with assembly name -->
<On Platform="UWP" Value="Base.Library.Uwp/Icons/icon.png" />
</OnPlatform>
</Image.Source>
</Image>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.