I’m using a combobox in my application and I am populating it with classes something like this:
namespace Foo.Bar{
public class Item
{
public string lastName;
public string firstName;
public Foo theMeatyPart;
}
}
I can populate the dropdown with “lastName, firstName” using an itemTamplate but then the selected value shows up as “Foo.Bar.Item”. How can I apply the same template to the selectedItem and also, have the search functionality work without overrriding the ToString method of Item?
Here is the xaml:
<Style x:Key="SearchComboStyle" TargetType="ComboBox">
<Style.Setters>
<Setter Property="Width" Value="150"></Setter>
</Style.Setters>
</Style>
<DataTemplate x:Key="SearchComboItemTemplate" >
<TextBlock DataContext="{Binding}">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0}, {1}">
<Binding Path="lastName"/>
<Binding Path="firstName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
<ComboBox ItemTemplate="{StaticResource SearchComboItemTemplate}" Style="{StaticResource SearchComboStyle}"
ItemsSource="{Binding Path=PhysiciansList, RelativeSource={RelativeSource AncestorType=local:ExamViewerControl, AncestorLevel=1}}" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" IsEditable="True" TextSearch.TextPath="Person.LastName" />
UPD:
Looks like you need to set SelectionBoxItemTemplate.You can use DisplayMemberPath or TextSearch.TextPath to enable search without modifying ToString().