i have a custom TabbedPage with an additional property. Like this:
public class CustomTabbedPage : Microsoft.Maui.Controls.TabbedPage {
public static readonly BindableProperty SeparatorLineColorProperty = BindableProperty.Create(nameof(SeparatorLineColor),
typeof(Color), typeof(CustomTabbedPage), null, defaultBindingMode: BindingMode.Default);
public Color SeparatorLineColor {
set => SetValue(SeparatorLineColorProperty, value);
get => (Color)GetValue(SeparatorLineColorProperty);
}
}
In the docs: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/?view=net-maui-8.0#page-handlers it is mentioned that TabbedPage handlers are TabbedRenderer in iOS and android. So i created in a partial class in iOS platform folder:
public partial class TabbedPageHandler : Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer{
private static void MapSeparatorLineColor(TabbedRenderer renderer, TabbedPage page) {
//Test
}
}
and in a partial class for the property mapper:
public partial class TabbedPageHandler {
public static PropertyMapper<CustomTabbedPage, TabbedPageHandler> PropertyMapper = new PropertyMapper<CustomTabbedPage, TabbedPageHandler>(Mapper) {
[nameof(CustomTabbedPage.SeparatorLineColor)] = MapSeparatorLineColor,
};
public TabbedPageHandler() : base(PropertyMapper) { //Error
}
}
The problem is, that the Microsoft.Maui.Controls.Handlers.Compatibility.TabbedRenderer
has no constructor for the mapped properties, but the static Mapper
field exists in TabbedRenderer
.
I tried to add my custom property in a static constructor:
public partial class TabbedPageHandler {
static TabbedPageHandler() {
Mapper.Add(nameof(CustomTabbedPage.SeparatorLineColor), MapSeparatorLineColor);
}
//public static PropertyMapper<CustomTabbedPage, TabbedPageHandler> PropertyMapper = new PropertyMapper<CustomTabbedPage, TabbedPageHandler>(Mapper) {
// [nameof(CustomTabbedPage.SeparatorLineColor)] = MapSeparatorLineColor,
//};
//public TabbedPageHandler() : base(PropertyMapper) {
//}
}
This works, but i have doubts this is the correct implementation. What is the correct way to map my custom property? I have expected that this works like entrys and the constructor from the base class takes my custom properties.
An issue is open at github: https://github.com/dotnet/maui/issues/19998. There is also a workaround. I think the MAUI-Team will fix it sometimes.