I want to create multiselect combobox control with telerik. The sample I found is in next link: https://docs.telerik.com/devtools/wpf/controls/radcombobox/features/multiple-selection
So, I created it like this:
<telerik:RadComboBox x:Name="radComboBox" AllowMultipleSelection="True" Height="30" Width="300" MultipleSelectionBoxTemplate="{StaticResource EmptyTemplate}">
<telerik:RadComboBoxItem Content="Alapattah" />
<telerik:RadComboBoxItem Content="Brickell Avenue" />
<telerik:RadComboBoxItem Content="Downtown Miami" />
<telerik:RadComboBoxItem Content="El Portal" />
</telerik:RadComboBox>
And the results are like it should be. But I want to show shorter text in "result" part of combobox, when it is closed. Now if I select Alapattah and El Portal, combobox value will be Alapattah, El Portal, and I would like to make it look like AL, EP.
So I created new Model, with 2 properties ID and Name, set in combobox DisplayMemberPath="Name" SelectedValuePath="ID", but still the results are the same, it only takes the value from DisplayMemberPath.
There is a DataTemplate for this multiselect:
<DataTemplate x:Key="EmptyTemplate">
<TextBlock FontWeight="Bold" FontFamily="Comic Sans" FontStyle="Italic" Text="{Binding}" />
</DataTemplate>
This way I get in combobox results like WpfApp1.Item, WpfApp1.Item...
If I set Text="{Binding Name}" I get nothing.
Here is the full code preview:
<Window x:Class="WpfApp10.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local="clr-namespace:WpfApp10"
mc:Ignorable="d"
Title="MainWindow"
Height="450"
Width="800">
<Grid>
<Grid.Resources>
<DataTemplate x:Key="EmptyTemplate">
<TextBlock FontWeight="Bold" FontFamily="Arial" FontStyle="Italic" Text="{Binding Name}" />
</DataTemplate>
</Grid.Resources>
<telerik:RadComboBox x:Name="radComboBox"
AllowMultipleSelection="True"
Height="30"
Width="300"
MultipleSelectionBoxTemplate="{StaticResource EmptyTemplate}">
</telerik:RadComboBox>
</Grid>
</Window>
So, is there any way to achieve this, maybe some custom template?
MultipleSelectionBoxTemplateproperty?{Binding}to{Binding YourProperty}whereYourPropertyis the property of the item that returns whatever you want to display?SelectedItemsin theMultipleSelectionBoxTemplate.