Hi all,
I have a problem regarding WPF combobox when using data template selector.
Basically, WPF combobox has a standard behaviour which will take you directly to the item that starts from a character if you type that character using keyboard. I don't know the official name for this functionality and will temporarily call it "Key Indexing".
I now want to create a ComboBox which displays its item differently. I achieved this using DataTemplateSelector;
<ComboBox SelectedItem="{Binding Selection}" x:Name="Input" ItemsSource="{Binding Parties}">
<ComboBox.ItemTemplateSelector>
<Editor:PartyTemplateSelector DefaultTemplate="{StaticResource Default}" NewTemplate="{StaticResource New}" OldTemplate="{StaticResource Old}"/>
</ComboBox.ItemTemplateSelector>
</ComboBox>
And the PartyTemplateSelector is:
public class PartyTemplateSelector : DataTemplateSelector
{
public DataTemplate DefaultTemplate
{
get; set;
}
public DataTemplate NewTemplate
{
get; set;
}
public DataTemplate OldTemplate
{
get; set;
}
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
var party = (Party) item;
if (party is OldDisplay)
{
return OldTemplate;
}
if(counterparty.NewLook)
{
return NewTemplate;
}
return DefaultTemplate;
}
}
It works fine apart from that the key indexing ability is lost. When I type a key while the combobox is dropped down, it does not take me to the item that starts from the character I typed.
Can anyone help me with this?
Regards.