这里我设置了ItemSource,
customApplicationHome.dataGridViewCustomApplication.ItemsSource = applicationList;
然后自动生成列方法未触发
private void dataGridViewCustomApplication_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
e.Column.Header = Utils.Util.SplitCamelCase(e.Column.Header.ToString());
}
和用于绑定上述方法的xaml是
<DataGrid x:Name="dataGridViewCustomApplication"
AlternationCount="2"
HeadersVisibility="Column"
Background="Transparent"
BorderThickness="0"
CanUserAddRows="False"
IsReadOnly="True"
ColumnWidth="*"
HorizontalAlignment="Left"
Margin="0,20,0,85"
VerticalAlignment="Top"
Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Binding,AncestorLevel=1}}"
Height="320"
Grid.ColumnSpan="2"
EnableRowVirtualization="False"
AutoGeneratingColumn="dataGridViewCustomApplication_AutoGeneratingColumn"
Sorting="DataGrid_Sorting"
LayoutUpdated="dataGrid_LayoutUpdated"
CopyingRowClipboardContent="DataGrid_CopyingRowClipboardContent" />
另请注意,我用作ItemSource的列表在其他数据网格中工作正常。