簡體   English   中英

從UWP庫加載圖標作為Xamarin.Forms中的圖像

[英]Load icons from UWP-library as image in Xamarin.Forms

我有以下情況:

  1. 我們已經/構建了一個Xamarin.Forms庫,其中還應該包含我們的常用圖標
  2. 此圖標應在該庫的XAML時代中使用,但也應在最終應用中使用

圖書館結構

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM