我的项目有BindableCollectio<string>
:
public BindableCollection<string> ProjectsList { get; set; }
public string SelectedProjectsList { get; set; } //project selected form combobox
目前,我只有项目名称。我将该列表绑定到ComboBox
中的简单WPF
。
<ComboBox x:Name="ProjectsList" SelectedValuePath="{Binding Path=SelectedProjectsList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Project
模型看起来像这样:
public class Project
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
在PorjectsList
中,我仅存储Project
的名称。
我的问题是,我们可以从BindableCollection
项目的id
中检索并且仍在组合框列表中显示项目名称吗?还是在CaliburnMicro
中有更好的解决方案?
您可以为此目的使用SelectedValuePath和DisplayMemberPath。您应该首先将ProjectsList
属性更改为BindableCollection<Project>.