WPF中如何动态的制作表格呢?如下图这样的表格
:
<Grid>
<DataGrid x:Name="datagrid1" HorizontalAlignment="Left" Margin="30,27,0,0" VerticalAlignment="Top" Height="213" Width="333" AutoGenerateColumns="True"/>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<TTest> t = new List<TTest>();
TTest t1 = new TTest { Number = 1, Content = "1" };
TTest t2 = new TTest { Number = 2, Content = "2" };
TTest t3 = new TTest { Number = 2, Content = "3" };
TTest t4 = new TTest { Number = 3, Content = "4" };
t.Add(t1);
t.Add(t2);
t.Add(t3);
t.Add(t4);
this.datagrid1.ItemsSource = t;
}
}
public class TTest
{
public Int32 Number { get; set; }
public String Content { get; set; }
}