2016-09-08 24 views
3

我有一個Master Detail page,我想在導航欄中設置圖標以顯示菜單。因此,我將我的圖像放入資產目錄(資產目錄>媒體>菜單)。如果我想從XAML引用該圖像,則該圖像不在資產目錄中時顯示。Xamarin.Forms:使用資產目錄中的圖像

我嘗試了不同的路徑,但它們都不起作用。 Debugging也不顯示任何圖像。看起來Xamarin.Forms不支持資產目錄,但事實並非如此。在一個正常的內容頁面上我有這個:

<ContentPage.ToolbarItems> 
<ToolbarItem Text="Configuration" Activated="OpenConfiguration" Order="Primary" Priority="0"> 
    <ToolbarItem.Icon> 
    <OnPlatform x:TypeArguments="FileImageSource"> 
     <OnPlatform.iOS>gear.png</OnPlatform.iOS> 
     <OnPlatform.Android>gear.xml</OnPlatform.Android> 
     <OnPlatform.WinPhone>Assets/gear.png</OnPlatform.WinPhone> 
    </OnPlatform> 
    </ToolbarItem.Icon> 
</ToolbarItem> 
</ContentPage.ToolbarItems> 

這工作沒有問題。在我MasterPage(頁,這是負責顯示在主詳細信息模板菜單項),我有這樣的:

<ContentPage.Icon> 
<OnPlatform x:TypeArguments="FileImageSource"> 
    <OnPlatform.iOS>menu.png</OnPlatform.iOS> 
    <OnPlatform.Android>menu.xml</OnPlatform.Android> 
    <OnPlatform.WinPhone>Assets/menu.png</OnPlatform.WinPhone> 
</OnPlatform> 
</ContentPage.Icon> 

Bascially,這是相同的代碼,但圖標顯示不出來。我得到的圖標只顯示如果我把圖像放入Resources文件夾...

但是我如何使用XAML資產目錄中的圖像?

回答

2

我從Xamarin得到的唯一回應是,FileImageSource不能用於資產目錄。這不完全正確,但是因爲每次不應該使用它時都不起作用。

相關問題