A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @Sreenivasan, Sreejith ,
Thanks for your question.
The NotImplementedException is happening because your class inherits from TabbedViewHandler. In the newer .NET MAUI environment, TabbedPage on iOS is actually still rendered using a compatibility layer called TabbedRenderer. Since the system relies on this compatibility layer for tabbed pages on iOS, trying to use a purely modern view handler throws an error and stops.
The NullReferenceException comes from trying to access the KeyWindow. Apple deprecated this property a while back to support multiple screens, so MAUI often sees it as completely empty. When your code tries to pull the RootViewController from that empty window, the app crashes.
You can refer to my following code example:
using System;
using UIKit;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Platform;
using Xamarin.Forms.Clinical6.Views;
namespace MAUI.Clinical6.Platforms.iOS.Controls
{
public class DashboardTabbedPageHandler : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.OldElement is DashboardTabPage oldPage)
{
oldPage.DashboardBadgeEvent -= OnDashboardBadgeEvent;
}
if (e.NewElement is DashboardTabPage newPage)
{
newPage.DashboardBadgeEvent += OnDashboardBadgeEvent;
}
}
private void OnDashboardBadgeEvent(object sender, int count)
{
UpdateBadge(count);
}
private void UpdateBadge(int count)
{
try
{
if (this.TabBar?.Items == null || this.TabBar.Items.Length == 0)
return;
var tabBarItem = this.TabBar.Items[0];
if (count <= 0)
{
tabBarItem.BadgeColor = UIColor.Clear;
tabBarItem.BadgeValue = null;
}
else
{
tabBarItem.BadgeColor = UIColor.FromRGB(190, 23, 23);
tabBarItem.BadgeValue = count.ToString();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Once you update this file, make sure handlers.AddHandler(typeof(DashboardTabPage), typeof(DashboardTabbedPageHandler)); is uncommented in your MauiProgram.cs and you should be good to go
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.