【发布时间】:2014-03-21 10:22:41
【问题描述】:
当 ComboBox 在 DataGrid 中实现时,我有两个关于将 ComboBox 绑定到列表对象的问题。但它们是如此相互关联,以至于我认为两个线程没有建设性。
我有很多类,我想在 xceed DataGrid 中显示它们的数据。我的 DataContext 设置为 ViewModelClass。它有一个 X 类对象的列表:
public class ViewModelClass
{
public IList<X> ListX { get; set; }
}
X 类看起来像这样。它有一个属性 ID 和一个 Y 类对象的列表。 该列表应该是我的 ComboBoxes 的 ItemsSource(在 DataGrid 中)。
public class X
{
public int Id { get; set; }
// this should be my ItemsSource for the ComboBoxes
public IList<Y> ListY { get; set; }
}
类 Y 和 Z 看起来像这样。它们是一些非常简单的类:
public class Y
{
public Z PropZ { get; set; }
}
public class Z
{
public string Name { get; set; }
}
我的 XAML 代码看起来像这样。
<Grid.Resources>
<xcdg:DataGridCollectionViewSource x:Key="ListX" AutoCreateItemProperties="False"
Source="{Binding Path=ListX,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay}" />
</Grid.Resources>
<p:DataGrid AutoCreateColumns="False"
ItemsSource="{Binding Source={StaticResource ListX},
UpdateSourceTrigger=PropertyChanged}">
<xcdg:Column Title="Id" FieldName="Id" />
<xcdg:Column Title="Functions" **FieldName="ListY"**>
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="PropZ.Name"
**ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataGridControl}}, Path=ItemsSource.ListY**}" SelectedValuePath="Funktion.FunktionId" />
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
现在我不知道,如何绑定ComboBox的ItemsSource,以便在我的X类中读取ListY的列表值?
那么我不知道我的函数列的字段名实际上是什么? 我输入了 ListY,因为它代表了我的 X 类中的属性 (IList)。但我觉得可能不太对。
非常感谢您的帮助!
【问题讨论】: