Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid binding DataTable 时数据不显示 #85

Open
JoeyMygithub opened this issue Jan 18, 2024 · 1 comment
Open

DataGrid binding DataTable 时数据不显示 #85

JoeyMygithub opened this issue Jan 18, 2024 · 1 comment

Comments

@JoeyMygithub
Copy link

DataGrid以mvvm模式binding Datatable 时数据并没有显示出来,当把style清除后数据才可以显示出来,怎么回事?

@yanjinhuagood
Copy link
Member

需要将AutoGenerateColumns="True"即可

1.xaml

<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding DataTableItems}"/>

2.cs

var dataTable = new DataTable();
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("Name", typeof(string));
dataTable.Rows.Add(1, "WPFDevelopers");
dataTable.Rows.Add(2, "WPFDevelopers");
dataTable.Rows.Add(3, "WPFDevelopers");
DataTableItems = dataTable;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants