我遇到了这个问题,如果您能帮助我,我将不胜感激。
我有一个带有public ObservableCollection<IProfile> Profiles { get; set; }
属性的ViewModel,它填充了DataGrid。
在DataGrid内部,有一个ComboBox列:
<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。
谢谢您的帮助。