RadComboBox MultipleSelectionBoxTempalte converter per item

1 Answer 155 Views
ComboBox
ofir
Top achievements
Rank 1
ofir asked on 17 Apr 2023, 12:54 PM | edited on 17 Apr 2023, 12:54 PM



I have a RadComboBox  thats bind to an Enum list like so


<telerik:RadComboBox HorizontalAligment="Streatch"
                                        x:Nmae="RadComboBox"
                                         HorizontalAligmentContent="Left"
                                         Margin ="0 0 10 0"
                                         StayOpenOnEdit="True"
                                         AllowMultipleSelection= "True"
                                         ItemSource="{Binding SignalTypes}"
                                         behaviors:SelectedItemsBinding.SourceList = "{Binding SelectedSignalTypes}"
                                         BorderThickness ="1"
                                         VerticalContentAligment="Center"
                                         CanAutocompleteSelectItems="True"
                                         EmptyTexy =" Select Signal Type"
                                        TextSearchMode="Contains"
                                           >
    <telerik:RadComboBox.MultipleSelectionBoxTemplate>
         <DataTemplate>
             <TextBlock Text="{Binding ElementName=RadComboBox , Path=SelectionBoxItem, Converter={StaticResource EnumValueToDisplayTextConverter}"/>
         </DataTemplate>
     </telerik:RadComboBox.MultipleSelectionBoxTemplate>
</telerik:RadComboBox>

Where SourceList is MultiSelector and EnumValueToDisplayTextConverter is a IValueConverter which convert from Enum to its corresponding DescriptonAttribute
My Problem is that in the converter value I'm a getting a string list, separated by the separator (i.e item1, item2, etc.) 
and im excepting 1 item inside my convertor, therefore my converter failed and I don't see any items at all at SelectionBox
i tried to use ItemsControl inside the template but for some reason i was getting 1 letter(char) of the Enum each time

P.S
I know i can create a new convertor and solve the problem, but i prefer not to

P.S2
I cant change my convertor

1 Answer, 1 is accepted

Sort by
1
Accepted
Martin Ivanov
Telerik team
answered on 20 Apr 2023, 07:52 AM

Hello Ofir,

By default, when the ComboBox control enables multiple items selection, there is a single visual presenter that displays the selected items. The presenter shows a string representation of the selected items separated by commas.

The MultipleSelectionBoxTemplate allows you to customize the visual presenter. Because the presenter is a single entity, the converter is called only once for the string representation of the selection (accessed with SelectionBoxItem), instead of being called multiple times.

You are getting single char per item in the case where you use ItemsControl, because the SelectionBoxItem property contains a string value, which is basically an array of chars. So, the ItemsControl interprets this as a collection of chars.

To achieve your requirement, you can use an ItemsControl like you already tried, but instead of SelectionBoxItem, you can use the SelectedItems collection of RadComboBox. For example:

<telerik:RadComboBox.MultipleSelectionBoxTemplate>
	 <DataTemplate>
		 <ItemsControl ItemsSource="{Binding ElementName=RadComboBox, Path=SelectedItems">
			<!-- you may want to change also the ItemsPanelTemplate in order to get horizontally oriented layout -->
			
			<ItemsControl.ItemTemplate>
				<DataTemplate>
					<TextBlock Text="{Binding Converter={StaticResource EnumValueToDisplayTextConverter}, Mode=OneWay}"/>
				</DataTemplate>
			</ItemsControl.ItemTemplate>
		 </ItemsControl>		 
	 </DataTemplate>
 </telerik:RadComboBox.MultipleSelectionBoxTemplate>

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox
Asked by
ofir
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or