如何防止 DataGrid WPF 中特定列的 alternatingRowBackground?
How do I Prevent alternatingRowBackground for particular columns in DataGrid WPF?
我的意思是,我不想在几列中的行中使用 alternatingRowBackground
<DataGrid
AutoGenerateColumns="False" AlternatingRowBackground="LightBlue" AlternationCount="2"
CanUserResizeRows="False" CanUserResizeColumns="False" CanUserAddRows="false"
CanUserDeleteRows="false" CanUserReorderColumns="false" CanUserSortColumns="false"
FontSize="15" FontWeight="SemiBold" ItemsSource="{Binding Collection}"
SelectedIndex="{Binding SelectedRowIndex, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Grid.ColumnSpan="2" RowHeaderWidth="0"
>
您可以使用 CellStyle
属性 为特定列中的单元格设置不同的样式。
<DataGrid AutoGenerateColumns="False" AlternatingRowBackground="LightBlue" AlternationCount="2"
CanUserResizeRows="False" CanUserResizeColumns="False" CanUserAddRows="false"
CanUserDeleteRows="false" CanUserReorderColumns="false" CanUserSortColumns="false"
FontSize="15" FontWeight="SemiBold" ItemsSource="{Binding Collection}"
SelectedIndex="{Binding SelectedRowIndex, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Grid.ColumnSpan="2" RowHeaderWidth="0">
<DataGrid.Resources>
<Style TargetType="DataGridCell" x:Key="WhiteBackgroundCell">
<Setter Property="Background" Value="White" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Prop1}" Header="Prop1" CellStyle="{StaticResource WhiteBackgroundCell}" />
<DataGridTextColumn Binding="{Binding Prop2}" Header="Prop2" />
</DataGrid.Columns>
</DataGrid>
我的意思是,我不想在几列中的行中使用 alternatingRowBackground
<DataGrid
AutoGenerateColumns="False" AlternatingRowBackground="LightBlue" AlternationCount="2"
CanUserResizeRows="False" CanUserResizeColumns="False" CanUserAddRows="false"
CanUserDeleteRows="false" CanUserReorderColumns="false" CanUserSortColumns="false"
FontSize="15" FontWeight="SemiBold" ItemsSource="{Binding Collection}"
SelectedIndex="{Binding SelectedRowIndex, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Grid.ColumnSpan="2" RowHeaderWidth="0"
>
您可以使用 CellStyle
属性 为特定列中的单元格设置不同的样式。
<DataGrid AutoGenerateColumns="False" AlternatingRowBackground="LightBlue" AlternationCount="2"
CanUserResizeRows="False" CanUserResizeColumns="False" CanUserAddRows="false"
CanUserDeleteRows="false" CanUserReorderColumns="false" CanUserSortColumns="false"
FontSize="15" FontWeight="SemiBold" ItemsSource="{Binding Collection}"
SelectedIndex="{Binding SelectedRowIndex, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Grid.ColumnSpan="2" RowHeaderWidth="0">
<DataGrid.Resources>
<Style TargetType="DataGridCell" x:Key="WhiteBackgroundCell">
<Setter Property="Background" Value="White" />
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Prop1}" Header="Prop1" CellStyle="{StaticResource WhiteBackgroundCell}" />
<DataGridTextColumn Binding="{Binding Prop2}" Header="Prop2" />
</DataGrid.Columns>
</DataGrid>