Skip to content

[BUG] WPF: ComboBox empty if bind to list<string> | ViewModelViewHost could not find a valid view for the view model #2008

@djonasdev

Description

@djonasdev

I have a ViewModel with the following property

public List<string> OperationModes { get; } = Enum.GetNames(typeof(EOperationMode)).ToList();

which I would like to bind to a ComboBox.

reactiveUI way | not working

this.OneWayBind(ViewModel, model => model.OperationModes, window => window.ComboBoxOperationMode.ItemsSource).DisposeWith(r);

enter image description here

If using reactiveUI to bind the list to the ComboBox, I get the following error in the console output.

console output

DefaultViewLocator: Failed to resolve view for view model type 'System.Object'.
DefaultViewLocator: Failed to resolve view for view model type 'System.Object'.
ViewModelViewHost: The ViewModelViewHost could not find a valid view for the view model of type System.String and value Passthrough.

xaml way | working

<ComboBox
	x:Name="ComboBoxOperationMode"
	ItemsSource="{Binding ViewModel.OperationModes}"/>

enter image description here

How can I solve this problem? Or is it not possible to bind a list<string> via reactiveUI?


Original Stackoverflow post: https://stackoverflow.com/questions/55825647/rx-combobox-empty-if-bind-to-liststring-viewmodelviewhost-could-not-find-a

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions