所以我得到了一個ObservableCollection的tmplist,其中我有幾個元素。爲什麼WPF 4.0中的DataGrid不顯示數據?
我將它連接到WPF 4.0中的DataGrid的ItemsSource,它不顯示任何內容。不添加任何colums。如果我添加斷點,我可以看到「的ItemsSource計數等於tmplist元素的數量,但列數等於0,這是爲什麼下面是一些代碼:
private ObservableCollection<Products> tmplist = new ObservableCollection<Products>();
public Products_view()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Products_view_Loaded);
}
void Produkty_widok_Loaded(object sender, RoutedEventArgs e)
{
grid.ItemsSource = tmplist;
}
和XAML:
<DataGrid Name="grid" CurrentCellChanged="grid_CurrentCellChanged" CellEditEnding="grid_CellEditEnding" RowEditEnding="grid_RowEditEnding" AlternatingRowBackground="#FFA0D1EA" AlternationCount="1" Background="#FF64A0BE" RowBackground="White" />
但tmplist已滿。我沒有在代碼中顯示它,但tmplist充滿了來自數據庫的元素。 – Mark 2010-06-28 18:32:35
爲踢腿嘗試使tmplist公共財產,而不是 – hkon 2010-06-28 18:40:34
創建了一個例子,在我做你的例子。它工作得很好.... ?? 你在你的一個事件處理程序中做任何事情嗎? – hkon 2010-06-28 18:48:23