XAML 使用上下文菜单时的数据网格行背景颜色

ws51t4hk  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(136)

请帮我
当IM使用行数据网格的上下文菜单时,背景更改为不同的颜色。如何修复它?standart backgroundbackground when using context menu

<DataGrid x:Name="dataGrid" AutoGenerateColumns="False" Grid.Row="1" CanUserAddRows="False"
                  ItemsSource="{Binding Model.FlatModel}" IsReadOnly="True" GridLinesVisibility="None" HeadersVisibility="Column" SelectionUnit="FullRow" CanUserSortColumns="False" RowHeight="20" >
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="Foreground" Value="Black"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}">
                    <Setter Property="ContextMenu" Value="{StaticResource cm}"/>
                </Style>
            </DataGrid.RowStyle>

            <DataGrid.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                   Color="#A6D8FF"/>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>
                </Style>

            </DataGrid.Resources>
            <DataGrid.Columns>
          
            </DataGrid.Columns>
        </DataGrid>

字符串

k3fezbri

k3fezbri1#

如果此上下文菜单,它工作得很好,即使在同一时间选择多个项目.

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsSelected}" Value="True"/>
                    <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGridRow}}, Path=ContextMenu.IsOpen}" Value="True"/>
                </MultiDataTrigger.Conditions>
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.CellStyle>

字符串

相关问题