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