Templates
If the default templates of the control do not suit your needs, you can easily define custom ones. The available templates for customizing are:
- ItemTemplate(DataTemplate): Defines the template of the items that are visualized in the drop-down list.
When the selection mode is single and the control is not editable if there is ItemTemplate set the same template will be visualized in the box part of the control when item is selected.
- SelectedItemTemplate(DataTemplate): Defines the template of the selected items that are visualized in the drop-down list.
- TokenTemplate(DataTemplate): Defines the template of the tokens that are visualized when multiple selection is performed.
- ShowMoreTemplate(DataTemplate): Defines the Template of the show more UI that gets visualized when the control is not focused and there is not enough space for all Tokens to be visualized when the selection mode is multiple.
Example with ItemTemplate and SelectedItemTemplate
Here is the ComboBox definition in XAML:
you need to add the following namespace:
the sample business model
and the ViewModel used:
The final result:
The Item and SelectedItem Template example can be found in our SDK Browser Application. You can find the applications in the Examples folder of your local Telerik UI for Xamarin installation or in the following GitHub repo.
Example with TokenTemplate and ShowMoreTemplate
Here is the ComboBox definition in XAML:
add the following namespace:
the sample business model
and the ViewModel used:
when the default TokenTemplate is overriden, you will need to implement custom logic for removing the tokens from the ComboBox:
here is a sample logic removing the token when adding TapGestureRecognizer to the Label:
Here is the how the Token and ShowMore Templates look:
The Token and ShowMore Template example can be found in our SDK Browser Application. You can find the applications in the Examples folder of your local Telerik UI for Xamarin installation or in the following GitHub repo.
Default Templates
Default ItemTemplate and SelectedItemTemplate of RadComboBox provide highlighting of the matching text while searching - this is implemented through a small auxiliary control in the templates, named RadHighlightLabel. RadHighlightLabel exposes UnformattedText
property that should be set to the complete text shown in the label and HighlightText
that should be set to the highlighted part of that text.
The example below shows the default ItemTemplate and SelectedItemTemplate with the RadHighlightLabel properly setup to highlight the search text coming from the RadComboBox input field.
First, add the required DataTemplates inside the Resources of your page:
Add the required namespace:
And here is the RadComboBox definition with the defined templates referenced:
Check the result in the screenshot below: