C# 动态选项卡栏BG颜色
我需要做一个选项卡栏,动态改变颜色,关于选择哪个选项卡。因此,在根页面上,它可以正常工作,我的tabbar xaml.cs中有:C# 动态选项卡栏BG颜色,c#,xaml,xamarin.forms,prism,C#,Xaml,Xamarin.forms,Prism,我需要做一个选项卡栏,动态改变颜色,关于选择哪个选项卡。因此,在根页面上,它可以正常工作,我的tabbar xaml.cs中有: public partial class BottomTabNavigation : TabbedPage { public BottomTabNavigation() => InitializeComponent(); private async void TabbedPage_CurrentPageChanged(object sender
public partial class BottomTabNavigation : TabbedPage
{
public BottomTabNavigation() => InitializeComponent();
private async void TabbedPage_CurrentPageChanged(object sender, EventArgs e)
{
var navigationPage = CurrentPage as NavigationPage;
var currentPage = navigationPage.CurrentPage;
if (currentPage.GetType() == typeof(FrontPage) || currentPage.GetType() == typeof(HerdList))
{
Tabbar.BarTextColor = Color.White;
Tabbar.BarBackgroundColor = Color.FromHex("#0c597a");
Tabbar.SelectedTabColor = Color.FromHex("#004864");
Tabbar.UnselectedTabColor = Color.White;
}
else
{
Tabbar.BarTextColor = Color.Black;
Tabbar.BarBackgroundColor = Color.White;
Tabbar.SelectedTabColor = Color.FromHex("#004864");
Tabbar.UnselectedTabColor = Color.Black;
}
}
}
所以我面临的问题是,当我导航到HerdList选项卡时,我可以通过列表打开一个新页面,其中选项卡栏需要从蓝色背景更改为白色背景。“TabbedPage\u CurrentPageChanged”并没有显示这一点,而我不更改选项卡,只更改页面
我怎样才能做到这一点
编辑
BottomTabNavigation.xaml:
<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"
xmlns:Menu="clr-namespace:ChrApp.Views.Menu"
xmlns:Letter="clr-namespace:ChrApp.Views.Letter"
x:Name="Tabbar"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
xmlns:CustomRenderer="clr-namespace:ChrApp.CustomRenderer"
CurrentPageChanged="TabbedPage_CurrentPageChanged"
NavigationPage.HasNavigationBar="False"
xmlns:Resources="clr-namespace:ChrApp.Resources"
>
<NavigationPage
Title="{Resources:Translate Front_Page}"
>
<x:Arguments>
<local:FrontPage/>
</x:Arguments>
<NavigationPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static CustomRenderer:Icon.House}"/>
</NavigationPage.IconImageSource>
</NavigationPage>
<NavigationPage
Title="{Resources:Translate Herd}"
>
<x:Arguments>
<local:HerdList/>
</x:Arguments>
<NavigationPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static CustomRenderer:Icon.Pig}"/>
</NavigationPage.IconImageSource>
</NavigationPage>
<NavigationPage
Title="{Resources:Translate More}"
>
<x:Arguments>
<Menu:MenuPage/>
</x:Arguments>
<NavigationPage.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeSolid}" Glyph="{x:Static CustomRenderer:Icon.Menu}"/>
</NavigationPage.IconImageSource>
</NavigationPage>
我注意到,选项卡页面\u CurrentPageChanged被触发。但是当我导航时,通过选择列表中的一个元素,它会显示当前页面是FrontPage,而不是HerdDetails,因为某些原因。我可以使用
this.currentpage
来更改特定选项卡时的条形图颜色。您能否提供更多有关导航到“HerdList”选项卡时所做操作的详细信息?感谢您的回复!:)我使用的是Prism库,所以我使用了NavigationService
,以及名为SelectTabAsync
的方法。我还为选项卡在根页面viewmodels(FrontPage、HerdList等)上实现了IActiveAware
,以检查选项卡何时被导航到。希望这足够详细:)顺便说一句。谢谢你的屏幕录音,不过有点浮华:)