は、グリッド上のAutoGenerateColumns、高さ、幅、たHorizontalAlignmentとVerticalAlignmentをプロパティを確認しています。あなたは自分のXAMLのデザイン面にツールボックスからそれをドラッグアンドドロップする場合は、このコードが生成されます:
<DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="254,64,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" />
はこれにそれを変更する:
<DataGrid HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch"/>
あなたの問題の両方を解決する必要があります。
EDIT:リストに含まれる要素のタイプは指定していませんが、自動的に生成される列はリストアイテムのパブリックプロパティにバインドされることに注意してください。
EDIT2: は今、あなたはあなたのリスト項目の種類を追加したことを、ここにサンプルがあります:
MainWindow.xaml.cs:
public partial class MainWindow: Window
{
public MainWindow()
{
InitializeComponent();
List<Author> list = new List<Author>
{
new Author { Name = "X Y", Content = "blah" },
new Author { Name = "W Z", Content = "blah blah" },
new Author { Name = "N N", Content = "blah blah blah" },
new Author { Name = "M M", Content = "blah blah blah blah" },
};
dataGrid1.AutoGenerateColumns = true;
dataGrid1.ItemsSource = list;
}
}
public class Author
{
public string Name { get; set; }
public DateTime PostedDate { get; set; }
public string ProjectTitle { get; set; }
public string Content { get; set; }
public string Link { get; set; }
}
MainWindow.xaml:
<Window x:Class="WpfApplication1.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>
<DataGrid HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch"/>
</Grid>
</Window>
出力:
「データがあります」が「データがあります」に変更されました。データは複数のデータであるが、複数のデータ項目を意味するものとしてデータを参照するのは正しくない。この状況では、複数のデータはまだデータ=データです。 –