Dom*_*nas 1 c# data-binding wpf reactiveui
在ViewModel是一个
public List<string> OperationModes { get; } = Enum.GetNames(typeof(EOperationMode)).ToList();
Run Code Online (Sandbox Code Playgroud)
我想绑定到ComboBox.
this.OneWayBind(ViewModel, model => model.OperationModes, window => window.ComboBoxOperationMode.ItemsSource).DisposeWith(r);
Run Code Online (Sandbox Code Playgroud)
如果使用reactiveUI将 绑定list到ComboBox,我会在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.
Run Code Online (Sandbox Code Playgroud)
<ComboBox
x:Name="ComboBoxOperationMode"
ItemsSource="{Binding ViewModel.OperationModes}"/>
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?或者无法绑定list<string>via reactiveUI?
Github 问题:https : //github.com/reactiveui/ReactiveUI/issues/2008
设置 的DisplayMemberPath属性ComboBox以避免使用ViewModelViewHost试图解析 的视图的string:
<ComboBox x:Name="ComboBoxOperationMode" DisplayMemberPath="." />
Run Code Online (Sandbox Code Playgroud)