{"record":{"id":"68529239ad7820f5","repo":"unoplatform/uno","slug":"unable-to-find-layergrid-template-part-685292","errorCode":null,"errorMessage":"Unable to find [LayerGrid] template part","messagePattern":"Unable to find \\[LayerGrid\\] template part","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.Maps/MapPresenter.iOS.cs","lineNumber":53,"sourceCode":"\n\t\tprivate MapControl? _owner;\n\n\t\tprotected override void OnApplyTemplate()\n\t\t{\n\t\t\tbase.OnApplyTemplate();\n\t\t\tUpdateOwnerSubscriptions();\n\n\t\t\t_mapGrid = GetTemplateChild(\"MapGrid\") as Grid;\n\t\t\t_layerGrid = GetTemplateChild(\"LayerGrid\") as Grid;\n\n\t\t\tif (_mapGrid == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Unable to find [MapGrid] template part\");\n\t\t\t}\n\n\t\t\tif (_layerGrid == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Unable to find [LayerGrid] template part\");\n\t\t\t}\n\n\t\t\t_internalMapView = new MKMapView();\n\n\t\t\t_mapGrid.Children.Add(_internalMapView);\n\t\t\t_internalMapView.ShowsUserLocation = false;\n\n\t\t\t_internalMapView.RegionChanged += OnRegionChanged;\n\n\t\t\tOnChildrenCollectionChanged(this, null);\n\n\t\t\tSetUpOverlayRenderer();\n\n\t\t\t_internalMapView.GetViewForAnnotation = OnGetViewForAnnotation!;\n\t\t}\n\n\t\tprivate IDisposable UpdateOwnerSubscriptions(MapControl owner)\n\t\t{","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.Maps/MapPresenter.iOS.cs#L35-L71","documentation":"InvalidOperationException thrown by MapPresenter.OnApplyTemplate (iOS) when GetTemplateChild(\"LayerGrid\") does not return a Grid. Same required template-part contract as the Android LayerGrid (error 27); the iOS presenter needs it for overlay layers.","triggerScenarios":"Custom ControlTemplate for MapControl on iOS omits the 'LayerGrid' Grid or uses a non-Grid element named 'LayerGrid', causing the 'as Grid' cast to return null.","commonSituations":"Cross-platform shared Style that defines LayerGrid as a different panel; theme override dropping the named element; renaming during refactoring.","solutions":["Ensure <Grid x:Name=\"LayerGrid\"/> (type Grid) is present in the template on iOS.","Mirror the default Generic.xaml template and only restyle non-structural elements.","Confirm element type is Grid, not Canvas/Border.","Revert to default template to confirm root cause is the custom template."],"exampleFix":"// before\n<Border x:Name=\"LayerGrid\"/>\n\n// after\n<Grid x:Name=\"LayerGrid\"/>","handlingStrategy":"validation","validationCode":"var layerGrid = mapControl.GetTemplateChild(\"LayerGrid\") as Grid;\nif (layerGrid == null) throw new InvalidOperationException(\"Custom template missing LayerGrid (iOS)\");","typeGuard":"bool TemplateHasLayerGrid(Control c)\n    => c.GetTemplateChild(\"LayerGrid\") is Grid;","tryCatchPattern":"try { /* OnApplyTemplate logic */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"LayerGrid\"))\n{ Log.Error(\"MapControl (iOS) template missing LayerGrid part\"); }","preventionTips":["Keep the LayerGrid Grid template part in iOS custom templates.","Ensure element type is Grid, not Canvas/Border.","Validate against the default template."],"tags":["maps","control-template","template-part","ios","uno-platform"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}