类别:类别 我们正在尝试将ICollection子类别(成员:Category1)与数据网格的组合框列绑定。
public partial class Category
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Category()
{
this.Category1 = new HashSet<Category>();
}
public long CategoryID { get; set; }
public string CategoryName { get; set; }
public Nullable<long> ParentID { get; set; }
public Nullable<int> Status { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Category> Category1 { get; set; }
public virtual Category Category2 { get; set; }
}
XAML代码:
public CategoryPage()
{
InitializeComponent();
bindCategoriesWithDataGrid();
}
private void bindCategoriesWithDataGrid()
{
entities = new RestaurantDatabaseEntities();
dgridCategories.ItemsSource = entities.Categories.ToList();
}
XAML UI:
<DataGrid AutoGenerateColumns="False" Height="226" Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Left" Margin="10,10,0,0"
Name="dgridCategories" VerticalAlignment="Top" Width="684" ColumnWidth="*"
RowEditEnding="dgCategory_RowEditEnding" CellEditEnding="dgCategory_CellEditEnding"
SelectionChanged="dgCategory_SelectionChanged" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding CategoryName}" Header="Category Name"
IsReadOnly="True" x:Name="dgrCategoryName">
</DataGridTextColumn>
<DataGridComboBoxColumn Header="Sub Category" ItemsSource="{Binding Category1}"
DisplayMemberPath="CategoryName"
x:Name="dgrSubCategories"/>
这不起作用,并且在数据网格中显示了空的组合框。