0

I have a ComboBox with Itemssource binding to a ListViewCollection on the VM. The ListViewCollection filters an ObservableCollection<ItemVM>

ItemVM has a property DisplayText which will be shown in the combobox.

The ComboBox Text is bound to a SearchString property on the VM of type string which is used for the ListCollectionView's filter.

I want my ItemVM to be templated so some items are displayed in red text based on propertyvalues on ItemVM.

The problem I have is that I cannot use DisplayPathName and itemstemplate at the same time.

Itemstemplate handles type ItemVM but the searchstring is string. This causes the text to sometime be the classname instead of the actual value.

If I would use strings instead of ItemVM it would work (but then I would have no properties to trigger color change from). What is the solution to make a searchable (filtered dropdown) combobox when the items are not of type string?

Johan
  • 502
  • 4
  • 18
  • Can you share code of what you are trying to explain? It helps us to give a suggestion/solution. – G K May 25 '19 at 08:59
  • It is for a company so I cannot share code. I can try to write some example code though based on it. – Johan May 25 '19 at 09:01
  • You can share a dummy or sample code on what you have done in a separate project (not on your actual ones) and update your question. – G K May 25 '19 at 09:03
  • Okay will create a concept code next week. – Johan May 25 '19 at 09:30
  • I just realized an ItemTemplateSelector might be what I am looking for so I can handle different types correct. I will try that – Johan May 25 '19 at 09:32
  • Simply swap `DisplayMemberPath="DisplayText"` with `TextSearch.TextPath="DisplayText"`. Ref [this post](https://stackoverflow.com/questions/1844156/wpf-iseditable-true-combobox-filled-with-objects-displays-the-tostring-as-the), you can keep `IsTextSearchEnabled="False"` to apply your own filter. – Funk May 25 '19 at 17:01
  • @Funk thanks your post looks promising. I will try it tomorrow. – Johan May 26 '19 at 11:42

0 Answers0