我在用 TabbedPage 以Xamarin的形式。在iOS中,我无法更新 标签页 徽章物品价值。我正在为iOS使用自定义渲染器。我的代码是:
TabbedPage
标签页
[assembly: ExportRenderer(typeof(TabbedPage), typeof(BottomTabbedPage))] namespace Graysons.iOS.Renderers { public class BottomTabbedPage : TabbedRenderer { public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); TabBar.UnselectedItemTintColor = UIColor.FromRGB(208, 208, 208); TabBar.BackgroundColor = UIColor.White; TabBar.Items[1].BadgeValue = "1"; TabBar.Items[2].BadgeValue = "1"; } } }
应用程序初始化时,首次显示徽章值。但问题是,当我的应用程序从后台模式打开时(即按下Home按钮并重新打开应用程序),我想更新徽章值。另外,在前台模式下,我想更新这个值。我怎样才能做到这一点?
我认为你应该把BadgeValue作为一个属性添加到你的TabbedPage中。 然后,您应该能够通过以下方式将其拔出:
if(Element is MyTabbedPage myTabbedPage) { TabBar.Items[1].BadgeValue = myTabbedPage.YourProperty; }