我正在使用Xamarin形式的TabbedPage
。在iOS中,我无法更新TabbedPage
徽章项目的值。我正在为iOS使用自定义渲染器。我的代码是:
[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";
}
}
}
首次初始化应用程序时,会显示徽章值。但是问题是我想从后台模式打开我的应用程序时更新徽章值(即,按“主页”按钮并重新打开应用程序)。另外,在前台模式下,我想更新此值。我该如何实现?
答案 0 :(得分:0)
我认为您应该将BadgeValue作为属性添加到TabbedPage。 然后,您应该可以使用以下方法将其拉出:
if(Element is MyTabbedPage myTabbedPage)
{
TabBar.Items[1].BadgeValue = myTabbedPage.YourProperty;
}