のようにC#コーディングで書けばOK
DataGrid dg = new DataGrid();
dg.AutoGenerateColumns = true;
dg.ItemsSource = db;
デシベルはどこですか
public ObservableCollection<Data> db = new ObservableCollection<Data>();
db.Add(new Data { Name = "person1", Description = "sssssss", Price = 15 });
db.Add(new Data { Name = "person2", Description = "okokok", Price = 12 });
列とデータを正常に生成します..しかし、XAMLで記述した場合、何も表示できません
<DataGrid ItemsSource="{Binding db}" AutoGenerateColumns="True"/>
このコレクションを DataGrid にバインドする方法が見つかりません。理由を教えてください
これは私のすべてのxamlです
<Window x:Class="testt.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Vertical" Name="Panel">
<TextBlock Name="count"/>
<DataGrid ItemsSource="{Binding db}" AutoGenerateColumns="True"/>
</StackPanel>
</Grid>
</Window>
ありがとうございました