XAML Datagrid单元格选择样式不起作用

时间:2016-05-05 18:10:22

标签: c# wpf xaml datagrid

我无法在某些条件下使用datagrid单元格选择样式。

我有以下风格:

<!--data grid-->
            <Style x:Key="DataGridCellSelect" TargetType="{x:Type DataGridCell}">
                <Style.Triggers>
                    <Trigger Property="DataGridCell.IsSelected" Value="True">
                        <Setter Property="Background" Value="{StaticResource DatagridRowSelected}" />
                    </Trigger>
                </Style.Triggers>
            </Style>

在数据网格中使用此代码可以正常工作:

<DataGrid.CellStyle>
                                <Style TargetType="{x:Type DataGridCell}">
                                    <Style.Triggers>
                                        <Trigger Property="DataGridCell.IsSelected" Value="True">
                                            <Setter Property="Background" Value="{DynamicResource DatagridRowSelected}" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </DataGrid.CellStyle>


However, no matter where I place it, it's not working in this datagrid:



 <DataGrid x:Name="dataGridExposureLeft" 
                    AutoGenerateColumns="False"
                    HorizontalAlignment="Stretch" 
                    Grid.Column="0"
                    Grid.ColumnSpan="3"
                    Grid.Row="5" 
                    Height="203"
                    IsReadOnly="True" 
                    ItemsSource="{Binding}"
                    Margin="10,0"
                    SelectionChanged="dataGridExposureLeft_SelectionChanged"
                    SelectionUnit="FullRow"
                    VerticalAlignment="Top">
                    <DataGrid.Resources>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="Background" Value="{StaticResource MainBackgroundColor}"/>
                            <Setter Property="BorderBrush" Value="White"/>
                            <Setter Property="BorderThickness" Value="1"/>
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        </Style>
                        <Style TargetType="{x:Type DataGridCell}">
                            <Setter Property="Height" Value="40"/>
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding ExposureID}" Visibility="Hidden"/>
                        <DataGridTextColumn Binding="{Binding Identifier}" Header="Identifier" Width="*"/>
                        <DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Source="{Binding ExposureImage}">
                                        <Image.Resources>
                                            <Style TargetType="{x:Type Image}">
                                                <Setter Property="RenderTransform">
                                                    <Setter.Value>
                                                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </Image.Resources>
                                    </Image>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <DataGridTextColumn Binding="{Binding Date}" Header="Date" Width="*"/>
                    </DataGrid.Columns>
                </DataGrid>

数据网格中的图像太大,以至于它们占据了整个可见网格。我做错了什么?

0 个答案:

没有答案