【发布时间】:2021-03-08 00:48:15
【问题描述】:
我正在尝试更改标签页中图标的颜色。我能够做到这一点,只需投到android:TabbedPage.BarItemColor="Red"。
但图标上的颜色必须根据当前显示的页面进行更改。
我设法在我的代码隐藏中更改了在页面上触发的这个方法:
Tabbepage.xaml.cs
private void TabbedPage_CurrentPageChanged(object sender, EventArgs e)
{
var navigationPage = CurrentPage as NavigationPage;
var currentPage = navigationPage.CurrentPage;
if (currentPage.GetType() == typeof(MenuPage))
{
Tabbar.BarTextColor = Color.White;
Tabbar.BarBackgroundColor = Color.FromHex("#004f3d");
}
else if (currentPage.GetType() == typeof(HerdList))
{
Tabbar.BarTextColor = Color.Black;
Tabbar.BarBackgroundColor = Color.White;
}
}
但我只能弄清楚如何将颜色设置为:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="ChrApp.Views.Tab.BottomTabNavigation"
xmlns:local="clr-namespace:ChrApp.Views"
x:Name="Tabbar"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarSelectedItemColor="Green"
android:TabbedPage.BarItemColor="Red"
xmlns:CustomRenderer="clr-namespace:ChrApp.CustomRenderer"
CurrentPageChanged="TabbedPage_CurrentPageChanged"
>
<NavigationPage
Title="Forside"
>
<x:Arguments>
<local:MenuPage/>
</x:Arguments>
<NavigationPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static CustomRenderer:Icon.House}"/>
</NavigationPage.IconImageSource>
</NavigationPage>
<NavigationPage
Title="Besætning"
>
<x:Arguments>
<local:HerdList/>
</x:Arguments>
<NavigationPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static CustomRenderer:Icon.Pig}"/>
</NavigationPage.IconImageSource>
</NavigationPage>
</TabbedPage>
我能否以某种方式将我的代码隐藏中的方法发送到我的视图模型,或者我可以从我的代码隐藏中访问演员表android:TabbedPage.BarItemColor="Red"?
提前致谢! ❤
【问题讨论】:
标签: c# xaml xamarin.forms tabbedpage