xamarin.forms - 如何在 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 时在视图或模型中设置图标的正确方法是什么?
解决方案
只需在标签页的子项中添加 icon 属性。这对我来说可以
<local:ContactUs Icon="Icons/History_Tab.png" Title="{Translate:TranslateExtension Text=NewMessage}" />
我的图标位于资源文件夹下,但您可以将它们放在任何地方。
推荐阅读
- sql-server - 从 SQL 查询派生值
- json - 从包含多个值的 json 输出文件中提取最新值
- python - 在 Multiindex 数据框中查找每个索引的第一次出现
- java - 阻塞 EntityManager 操作
- excel - Excel VBA TextToColum 部分使用 MS 项目日期
- r - 在 R 中编写一个简单的函数
- javascript - 使用 fetch() 将表单数据发布到数据库(mongodb)并在视图中呈现表单的主体(最好是 EJS)
- python - Django中隐式多对多(多对多对多)关系的模型字段
- docker - Jenkins 的 Docker Swarm 插件无法解析环境变量
- c# - Linq to SQL Left Join with where 子句寻找条件或空