You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI中iOS平台ToolbarHandler追加映射未触发问题

MAUI中iOS平台ToolbarHandler自定义映射不触发问题

我需要自定义Android和iOS平台的Toolbar,因此弃用了旧渲染器,为ToolbarHandler追加映射:

Android平台(Platforms.Android.MainApplication.cs)代码正常执行

[Application]
public class MainApplication : MauiApplication
{
    public MainApplication(IntPtr handle, JniHandleOwnership ownership)
        : base(handle, ownership)
    {
    }

    protected override MauiApp CreateMauiApp() {

        ToolbarHandler.Mapper.AppendToMapping("CustomToolbarMapper", (handler, toolbar) =>
        {
            var materialToolbar = handler.PlatformView;
            materialToolbar.ContentInsetStartWithNavigation = 0;
            materialToolbar.TitleCentered = true;
        });

        return MauiProgram.CreateMauiApp();
    }
}

iOS平台(Platforms.iOS.AppDelegate.cs)追加的映射动作未触发

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
    protected override MauiApp CreateMauiApp() {

        System.Diagnostics.Debug.WriteLine("IN CREATE MAUI APP iOS");

        ToolbarHandler.Mapper.AppendToMapping("CustomToolbarMapper2", (handler, toolbar) =>
        {
            // 从未执行到此处!
            System.Diagnostics.Debug.WriteLine("IN TOOLBAR HANDLER");
        });

        return MauiProgram.CreateMauiApp();
    }
}

重现步骤

  • 为现有ToolbarHandler.Mapper属性追加自定义映射
  • 在iOS平台运行项目

预期结果

追加的映射动作中的代码被调用

当前结果

追加的映射动作中的代码未被调用

公开复现仓库:JordiCasas/ToolbarHandlerIssue

Android平台正常运行截图:标题已居中

内容的提问来源于stack exchange,提问作者jordi casas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 12:30:18