0
我将ReactiveList绑定到视图代码隐藏中的ComboBox并获取错误System.Exception:'无法找到'Value1'的视图。。将ReactiveList绑定到ComboBox无法找到视图错误
ViewModel.cs
public class SourceItem
{
public override string ToString()
{
return Name;
}
public string Name { get; set; }
}
public class ViewModel : ReactiveObject
{
public ReactiveList<SourceItem> SourceList { get; } = new ReactiveList<SourceItem>();
public SourceItem SelectedSourceItem { get; set; }
public ViewModel()
{
SourceList.Add(new SourceItem() {Name = "Value1"});
}
}
View.xaml
<ComboBox Name="Source"/>
View.cs
this.OneWayBind(ViewModel, x => x.SourceList, x => x.Source.ItemSource);
this.Bind(ViewModel, x => x.SelectedSourceItem, x => x.Source.SelectedItem);
是否有SIMP le方式强制ToString()
用于显示值?
您需要DataTemplate for ComboBox – Coding4Fun