gpt4 book ai didi

c# - RX : ComboBox empty if bind to list | ViewModelViewHost could not find a valid view for the view model

转载 作者:行者123 更新时间:2023-12-02 20:01:15 27 4
gpt4 key购买 nike

ViewModel是一个

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

我想绑定(bind)到 ComboBox .

reactiveUI 方式 |不工作

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

enter image description here

如果使用 reactiveUI绑定(bind) listComboBox ,我在 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 方式 |工作

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

enter image description here

我该如何解决这个问题?或者无法绑定(bind) list<string>通过reactiveUI


Github 问题:https://github.com/reactiveui/ReactiveUI/issues/2008

最佳答案

设置DisplayMemberPath ComboBox 的属性(property)避免使用 ViewModelViewHost试图解析 string 的 View :

<ComboBox x:Name="ComboBoxOperationMode" DisplayMemberPath="." />

关于c# - RX : ComboBox empty if bind to list<string> | ViewModelViewHost could not find a valid view for the view model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55825647/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com