【发布时间】:2019-11-29 17:23:54
【问题描述】:
我遇到了这个问题,如果您能帮我解决这个问题,我将不胜感激。
我有一个带有 public ObservableCollection<IProfile> Profiles { get; set; } 属性的 ViewModel,它填充了一个 DataGrid。
在 DataGrid 内部,有一个 ComboBox Column:
<DataGridComboBoxColumn
Header="Header"
Width="*"
Visibility="{Binding SelectedType, Converter={Commons:ProfileVisibilityConverter}}"
ItemsSource="{Binding PotentialReinforces}"
SelectedValueBinding="{Binding SectionID, UpdateSourceTrigger=LostFocus, Mode=TwoWay}"
DisplayMemberPath="Name"
SelectedValuePath="ReinforceID"/>
我不能使用静态 ItemSource,因为每行的 ComboBox 源与其他行相比是不同的。因此,我需要动态的 ItemSource
在 Profile 类中,我定义了以下的 PotentialReinforces,它为每个对象提供了合适的结果:
public ObservableCollection<Section> PotentialReinforces
{
get
{
var Ids = this != null ? Database.Reinforces.Get.Where(x => x.BlongID == this.SectionID).Select(x => x.SectionID.Value) : new int[0];
if (Ids.Count() > 0)
{
return new ObservableCollection<Section>(Database.ReinforceSections.Get.Where(x => Ids.Contains(x.SectionID)));
}
else return null;
}
}
当我调试代码时,根据我的设计,每个 Profile 对象都有潜在的集合,但 Combobox 不将该集合识别为其 ItemSource。
感谢您的帮助。
【问题讨论】:
标签: c# wpf datagridcomboboxcolumn itemsource