In ItemsView
and subclasses of ItemsView
such as ListBox
, ComboBox
, ..., ReactiveUI automatically sets the ItemTemplate
property. This makes it easy to add a bunch of viewmodels to a list, bind the list to an ItemsView
and have the correct views for each viewmodel.
However, sometimes this behavior is not desirable. For example, after binding a list of regular objects to a ComboBox
I get the exception "Couldn't find view for MyNamespace.MyObject
".
I could fix this by setting the DisplayMemberPath
property on the ComboBox, however this property is not known at compile time. I want to bind DisplayMemberPath
from the ViewModel to the View. Unfortunately, this produces the following exception: "InvalidOperationException: Cannot set both DisplayMemberPath and ItemTemplate"
How can I fix this?