how can i specify MultipleSelectionBoxTemplate which i can access properties of selected items
i have an employee class
public class Employee {
public string Firstname {get;set;}
public string Lastname {get;set;}
}
I am using Telerik radCombobox in my wpf application to display list of employee
<telerik:RadComboBox x:Name="radComboBox"
Width="200"
AllowMultipleSelection="True"
ItemsSource="{Binding Path=EmployeeList}"
>
<telerik:RadComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Lastname}" />
</DataTemplate>
</telerik:RadComboBox.ItemTemplate>
this works fine for itemtemplate but when i select an item the display text in combobox show name of Employee class not the Lastname i tried
<telerik:RadComboBox.MultipleSelectionBoxTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Lastname}" />
</DataTemplate>
</telerik:RadComboBox.MultipleSelectionBoxTemplate>
i get no result , the combobox displayvalue of selected item is always empty.
i tried another solution
<telerik:RadComboBox.MultipleSelectionBoxTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=SelectedItems,Converter={StaticResource SelectionToCustomStringCoverter}}" />
</DataTemplate>
</telerik:RadComboBox.MultipleSelectionBoxTemplate>
this neither work , the converter always execute at first selection
this is really crazy spending 4 hours to figure out a simple thing , so my question is how can i specify MultipleSelectionBoxTemplate which i can access properties of selected items .
CodePudding user response:
this neither work , the converter always execute at first selection
You need to bind to a property that is actually set when the selection changes, such as the Count
property of the SelectedItems
collection.
Try using a multi value converter and a MultiBinding
:
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource SelectionToCustomStringCoverter}">
<Binding Path="SelectedItems" RelativeSource="{RelativeSource AncestorType=telerik:RadComboBox}"/>
<Binding Path="SelectedItems.Count" RelativeSource="{RelativeSource AncestorType=telerik:RadComboBox}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
You will then get the currently selected items from values[0]
in the converter.