嗯,我有一些像這樣的數據對象的數據類:內容不會出現在數據網格
private ObservableCollection<bool> check = new ObservableCollection<bool>();
public ObservableCollection<bool> Check
{
get { return check; }
set
{
check = value;
Notify("check");
}
}
private ObservableCollection<string> user = new ObservableCollection<string>();
public ObservableCollection<string> User
{
get { return user; }
set
{
user = value;
Notify("user");
}
}
而在主窗口我加了這樣一個DataGrid:
<DataGrid AutoGenerateColumns="False"
Name="dataGrid1"
CanUserAddRows="False" CanUserSortColumns="False" CanUserResizeColumns="True" CanUserReorderColumns="False"
ItemsSource="{Binding}">
<DataGrid.Columns >
<DataGridCheckBoxColumn Header = "" Binding="{Binding Check, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MinWidth="50" />
<DataGridTextColumn Header = "User" Binding="{Binding User, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MinWidth="50" />
</DataGrid.Columns>
</DataGrid>
對於整個窗口datakontext ist設置爲數據類。在構造函數中,我調用了「DataContext = theData」;我在數據類的構造函數中添加了一些值,並通過運行程序來驗證此類的實例。值正確添加到ObservableCollection。
但是這些值沒有顯示在數據網格中。爲什麼?
好吧,我寫了一個新的YourDataObject calss實現了我的現有數據類旁邊的一些其他數據的Veiw模型。這有點不同,但我更多地瞭解它如何工作,我很高興! – tux007