我在DataGrid
中发现了非常奇怪的行为。我无法弄清楚为什么会发生这种情况,但如果列标题中有DataGrid
或"."
点,则"/"
不会显示值。
XAML:
<Window x:Class="DataGridWpfApplication.MainWindow"
<!--the code omitted for the brevity-->
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid Name="dataGrid" AutoGenerateColumns="True"/>
</Grid>
</Window>
代码隐藏:
public MainWindow()
{
InitializeComponent();
PopulateDataGrid();
}
private void PopulateDataGrid()
{
var _ds = new DataSet("Test");
var employeeDataTable = new DataTable();
employeeDataTable = _ds.Tables.Add("DT");
for (int i = 0; i < 50; i++)
{
employeeDataTable.Columns.Add(i.ToString() + ".");//No Data in values
//employeeDataTable.Columns.Add(i.ToString());//Data in values
}
for (int i = 0; i < 2; i++)
{
var theRow = employeeDataTable.NewRow();
for (int j = 0; j < 50; j++)
{
if (j % 2 == 0)
{
theRow[j] = "a";
}
else
theRow[j] = "b";
}
employeeDataTable.Rows.Add(theRow);
}
dataGrid.ItemsSource = employeeDataTable.AsDataView();
}
我的问题是如何才能把#34;。&#34;和&#34; /&#34;列标题和显示数据?
更新
I wrote an answer in the previous question. Please, go here!:)