我有一个datagrid,它只在第一列中显示值,而其他单元格中有值。这是我的代码。
<Grid ShowGridLines="False">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DataGrid HorizontalAlignment="Left" VirtualizingStackPanel.IsVirtualizing="False" GridLinesVisibility="None" IsReadOnly="True"
Name="AvdrEventsDataGrid" VerticalAlignment="Top" Grid.Row="0" ItemsSource="{Binding}" Loaded="AvdrEventsDataGrid_Loaded" CanUserSortColumns="False">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<!--<Setter Property="Background" Value="Black" />
<Setter Property="Foreground" Value="White" />-->
<!--<Setter Property="FontFamily" Value="Wingdings" />-->
<Setter Property="FontSize" Value="12" />
</Style>
</DataGrid.Resources>
</DataGrid>
<Button Content="Run!" Height="23" HorizontalAlignment="Left" Name="btnRun" VerticalAlignment="Top"
Margin="20,0,0,0" Width="75" Grid.Row="1" Click="btnRun_Click" />
</Grid>
DataTable _resulTable=new DataTable();
AvdrEventBuilder avdrEventBuilder=new AvdrEventBuilder();
_resulTable = avdrEventBuilder.GetEventData();
AvdrEventsDataGrid.DataContext = _resulTable;
此外,我正在更改第一列的颜色
int i = 0;
foreach (var row in _resulTable.Rows)
{
var cell = AvdrEventsDataGrid.GetCell(i, 0);
cell.Background = Brushes.Gray;
cell.Foreground = Brushes.White;
i++;
cell.Width = 100;
}
问题是我只能在第一列中看到值,即使其他数据集列中有值。我也试过AvdrEventsDataGrid.ItemsSource = @object;这使用了一组类对象。它显示相同的空白值。请帮忙。