Hi,
On one of our items on the tabbedPage menu we want to show a badge value on IOS devices.
I know there is no standard function for this in Xamarin forms and we need to use a Custom Render but how do we implement this?
There is one example on this forum but I think our situation is a little different:
http://forums.xamarin.com/discussion/comment/70217/#Comment_70217
We have one mainPage which derives from TabbedPage.
public partial class MainPage : TabbedPage
{
ShoppingCartPage shopCartPage;
public MainPage()
{
InitializeComponent();
shopCartPage = GetShoppingCartPage();
this.Children.Add(new NavigationPage(GetActionsPage()) { Title = "Acties" });
this.Children.Add(new NavigationPage(GetScanPage()) { Title = "Scannen" });
this.Children.Add(new NavigationPage(GetMainSearchPage()) { Title = "Winkelen" });
this.Children.Add(new NavigationPage(shopCartPage) { Title = "Winkelmandje" });
this.Children.Add(new NavigationPage(GetProfilePage()) { Title = "Profiel" });
}
On the shopCartPage menu item we want to show a badge.
This is the ShopcartPage:
public partial class ShoppingCartPage : ContentPage
{
private ShoppingCartListView lvProducts;
public ShoppingCartPage()
{
InitializeComponent();
LoadProductListViewDetails();
}
Nothing special going on there.
So I build a custom render for this page:
`[assembly: ExportRenderer(typeof(ShoppingCartPage), typeof(ShoppingCartRender))]
namespace NinaEasyOrderApp.IOS
{
public class ShoppingCartRender : PageRenderer
{
ShoppingCartPage shoppingCartPage;
public ShoppingCartRender()
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.TabBarItem = new UITabBarItem("Initial Title", UIImage.FromBundle("Icon-Small.png"), 4);
this.TabBarItem.BadgeValue = "3";
//var navigationCtrller = ViewController as UIViewController;
//navigationCtrller.TabBarItem =
//navigationCtrller.TabBarItem.BadgeValue = "5";
// BadgeValue did get initialized, but it's not changed
// if later on blueNavigationPage.Title gets changed.
// **How to update BadgeValue?**
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
shoppingCartPage = e.NewElement as ShoppingCartPage;
this.TabBarItem.Title = "Test";
}
}
}`
But there is no badge and also the title is still "Winkelmandje".....
Anyone knows a solution?