dotnet/maui · error · NotSupportedException
You are using an instance of {nameof(DataTemplateSelector)}
Error message
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 What it means
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.
Source
Thrown at src/Controls/src/Core/BindableLayout/BindableLayout.cs:321
_itemsSource = itemsSource;
if (_itemsSource is INotifyCollectionChanged c)
{
_collectionChangedProxy.Subscribe(c, _collectionChangedEventHandler);
}
if (!_isBatchUpdate)
{
CreateChildren();
}
}
void SetItemTemplate(DataTemplate itemTemplate)
{
if (itemTemplate is DataTemplateSelector)
{
throw 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");
}
_itemTemplate = itemTemplate;
if (!_isBatchUpdate)
{
CreateChildren();
}
}
void SetItemTemplateSelector(DataTemplateSelector itemTemplateSelector)
{
_itemTemplateSelector = itemTemplateSelector;
if (!_isBatchUpdate)
{
CreateChildren();
}View on GitHub (pinned to f377ff1c5e)
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.
Example fix
<!-- before -->
<StackLayout BindableLayout.ItemTemplate="{StaticResource MySelector}" />
<!-- after -->
<StackLayout BindableLayout.ItemTemplateSelector="{StaticResource MySelector}" /> Defensive patterns
Strategy: type-guard
Validate before calling
// Route selectors to the correct property before assignment.
static void SetTemplate(BindableObject layout, object template)
{
if (template is DataTemplateSelector sel)
BindableLayout.SetItemTemplateSelector(layout, sel);
else if (template is DataTemplate dt)
BindableLayout.SetItemTemplate(layout, dt);
} Type guard
static bool IsSelector(object template) => template is DataTemplateSelector;
Prevention
- 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.
When it happens
Trigger: SetItemTemplate receives a DataTemplate whose runtime type 'is DataTemplateSelector' is true, so the NotSupportedException is thrown with the message redirecting you to ItemTemplateSelector.
Common situations: 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.
Related errors
- The Map.ItemTemplate property only supports DataTemplate. Se
- ItemTemplate count has exceeded the limit of {ViewTypeCount}
- DataTemplateSelector.OnSelectTemplate must not return anothe
- ItemTemplate count has exceeded the limit of {ViewTypeCount}
- InsertPageBefore is not supported globally on GTK, please us
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e53e00e3b5413b11.
Report an issue: GitHub.