{"record":{"id":"e53e00e3b5413b11","repo":"dotnet/maui","slug":"you-are-using-an-instance-of-nameof-datatemplates","errorCode":null,"errorMessage":"You are using an instance of {nameof(DataTemplateSelector)} to set the {nameof(BindableLayout)}.{BindableLayout.ItemTemplateProperty.PropertyName} property. Use {nameof(BindableLayout)}.{BindableLayout.ItemTemplateSelectorProperty.PropertyName} property instead to set an item template selector","messagePattern":"You are using an instance of (.+?) to set the (.+?)\\.(.+?) property\\. Use (.+?)\\.(.+?) property instead to set an item template selector","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindableLayout/BindableLayout.cs","lineNumber":321,"sourceCode":"\n\t\t\t_itemsSource = itemsSource;\n\n\t\t\tif (_itemsSource is INotifyCollectionChanged c)\n\t\t\t{\n\t\t\t\t_collectionChangedProxy.Subscribe(c, _collectionChangedEventHandler);\n\t\t\t}\n\n\t\t\tif (!_isBatchUpdate)\n\t\t\t{\n\t\t\t\tCreateChildren();\n\t\t\t}\n\t\t}\n\n\t\tvoid SetItemTemplate(DataTemplate itemTemplate)\n\t\t{\n\t\t\tif (itemTemplate is DataTemplateSelector)\n\t\t\t{\n\t\t\t\tthrow new NotSupportedException($\"You are using an instance of {nameof(DataTemplateSelector)} to set the {nameof(BindableLayout)}.{BindableLayout.ItemTemplateProperty.PropertyName} property. Use {nameof(BindableLayout)}.{BindableLayout.ItemTemplateSelectorProperty.PropertyName} property instead to set an item template selector\");\n\t\t\t}\n\n\t\t\t_itemTemplate = itemTemplate;\n\n\t\t\tif (!_isBatchUpdate)\n\t\t\t{\n\t\t\t\tCreateChildren();\n\t\t\t}\n\t\t}\n\n\t\tvoid SetItemTemplateSelector(DataTemplateSelector itemTemplateSelector)\n\t\t{\n\t\t\t_itemTemplateSelector = itemTemplateSelector;\n\n\t\t\tif (!_isBatchUpdate)\n\t\t\t{\n\t\t\t\tCreateChildren();\n\t\t\t}","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindableLayout/BindableLayout.cs#L303-L339","documentation":"Thrown by BindableLayout.SetItemTemplate when the object assigned to the ItemTemplate bindable property is actually a DataTemplateSelector. BindableLayout has a dedicated ItemTemplateSelector property for selectors; using the plain ItemTemplate slot for a selector is unsupported and is rejected explicitly so behavior does not silently degrade.","triggerScenarios":"SetItemTemplate receives a DataTemplate whose runtime type 'is DataTemplateSelector' is true, so the NotSupportedException is thrown with the message redirecting you to ItemTemplateSelector.","commonSituations":"Binding a DataTemplateSelector instance to ItemTemplate in XAML by mistake; sharing a selector resource across a CollectionView (selector-aware) and a BindableLayout (needs the dedicated property); renaming a property from ItemTemplateSelector to ItemTemplate during refactor.","solutions":["Assign the selector to BindableLayout.ItemTemplateSelectorProperty instead of ItemTemplateProperty.","If you intended a single template, replace the DataTemplateSelector with a plain DataTemplate on ItemTemplate.","Double-check XAML: the attached property must read BindableLayout.ItemTemplateSelector, not ItemTemplate."],"exampleFix":"<!-- before -->\n<StackLayout BindableLayout.ItemTemplate=\"{StaticResource MySelector}\" />\n<!-- after -->\n<StackLayout BindableLayout.ItemTemplateSelector=\"{StaticResource MySelector}\" />","handlingStrategy":"type-guard","validationCode":"// Route selectors to the correct property before assignment.\nstatic void SetTemplate(BindableObject layout, object template)\n{\n    if (template is DataTemplateSelector sel)\n        BindableLayout.SetItemTemplateSelector(layout, sel);\n    else if (template is DataTemplate dt)\n        BindableLayout.SetItemTemplate(layout, dt);\n}","typeGuard":"static bool IsSelector(object template) => template is DataTemplateSelector;","tryCatchPattern":null,"preventionTips":["Remember: ItemTemplateSelector for selectors, ItemTemplate for single templates.","In XAML, double-check the attached property name when binding a shared selector resource.","Keep selector resources named '...Selector' to signal their intended property."],"tags":["bindable-layout","datatemplate","datatemplateselector","not-supported"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}