首页 > 解决方案 > 如何在 Prism 中为 Xamarin Forms 中的 TabbedPage 设置图标属性?

问题描述

我在这里扩展了 prism 示例,还包括图标和一些额外的导航。我的目标是添加类似于下面的代码(图标信息所在的位置),并且不确定如何将其正确添加到我的视图或视图模型中。

<?xml version="1.0" encoding="UTF-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
             prism:ViewModelLocator.AutowireViewModel="True"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:WebOfTrust.Views"
             x:Class="WebOfTrust.Views.Client.WebOfTrustMainPage"
             Title="{Binding Title}">
    <TabbedPage.Children>

      <!-- HOW DO I SET AN ICON FOR THESE? Either in the View or Model? --> 
     <NavigationPage Title="Contacts" >
        <x:Arguments> 
            <local:Client.MyPeople.MyPeopleList/>  
        </x:Arguments> 
    </NavigationPage> 

    <NavigationPage Title="Places" Icon="Image7DoesntWork.png">
        <x:Arguments>
             <local:Client.MyPlaces.MyPlacesList/>    
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="Docs" Icon="Image7DoesntWork.png">
        <x:Arguments>
           <local:Client.MyWallet.WalletCards/>  
        </x:Arguments>
    </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>

通常有效的方法

我通常在视图中有一个导航页面,我在其中指定下面的图标。

<NavigationPage Title="Trust Anchor List">
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="tab_feed.png"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <local:Client.TrustAnchorList />
            </x:Arguments>
 </NavigationPage>

问题

使用 Prism 时在视图或模型中设置图标的正确方法是什么?

在此处输入图像描述

标签: xamarin.formsprismprism-6tabbedpage

解决方案


只需在标签页的子项中添加 icon 属性。这对我来说可以

<local:ContactUs Icon="Icons/History_Tab.png" Title="{Translate:TranslateExtension Text=NewMessage}" />

我的图标位于资源文件夹下,但您可以将它们放在任何地方。


推荐阅读