我有DataGrid:
<DataGrid name:"DG" ItemSource="{Binding}"/>
并以这样的方式填充:
DG.ItemsSource = DataSet.Tables[0].DefaultView;
我需要更改列标题。我用这种方式:
<DataGrid name:"DG" ItemSource="{Binding}" Loaded="FormatColumns"/>
DG.Columns[i].Header = "Name";
在我的PC上,它工作得很好,但是当我在PC上使用Windows启动这个软件时,我意识到DG
有0列作为Loaded
。
这里有很多代码,如:
DG.Columns[i].Header = "Name";
最好是在另一件事之后再用。那么,这里有什么事件我可以处理并手动设置所有标头吗?
发布于 2016-06-06 05:46:02
刚刚意识到。如果DataSet
为空,则在Windows上启动此程序时,DataGrid
不会填充空列。这里的DataGrid
完全是空的。
因此,这里有一个肮脏的解决方案:
if (DataGrid.Columns.Count == 0) return;
https://stackoverflow.com/questions/37650135
复制相似问题