选中DataGrid的Cell而不是row

来源:互联网 发布:ucjiz软件免费下载 编辑:程序博客网 时间:2024/06/06 05:44
主要是针对DataGridCellsPresenter而不是SelectiveScrollingGrid,使用时DataGridRow应用这个style就可以了。

<Style x:Key="grdStudyListDataGridRowStyle" TargetType="{x:Type DataGridRow}">                <Setter Property="SnapsToDevicePixels" Value="true"/>                <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>                <Setter Property="ValidationErrorTemplate">                    <Setter.Value>                        <ControlTemplate>                            <TextBlock Foreground="Red" Margin="2,0,0,0" Text="!" VerticalAlignment="Center"/>                        </ControlTemplate>                    </Setter.Value>                </Setter>                <Setter Property="Template">                    <Setter.Value>                        <ControlTemplate TargetType="{x:Type DataGridRow}">                            <Grid x:Name="DGR_Border" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" Width="Auto">                                <SelectiveScrollingGrid x:Name="selectiveScrollingGrid" d:LayoutOverrides="Width">                                    <SelectiveScrollingGrid.ColumnDefinitions>                                        <ColumnDefinition Width="Auto"/>                                        <ColumnDefinition Width="*"/>                                    </SelectiveScrollingGrid.ColumnDefinitions>                                    <SelectiveScrollingGrid.RowDefinitions>                                        <RowDefinition Height="*"/>                                        <RowDefinition Height="Auto"/>                                    </SelectiveScrollingGrid.RowDefinitions>                                    <Border x:Name="bdCell"  Grid.Column="1" HorizontalAlignment="Left">                                        <DataGridCellsPresenter ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"/>                                    </Border>                                    <DataGridDetailsPresenter Grid.Column="1" Grid.Row="1" SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Visibility="{TemplateBinding DetailsVisibility}"/>                                    <DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="Collapsed"/>                                </SelectiveScrollingGrid>                            </Grid>                            <ControlTemplate.Triggers>                                <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True">                                    <Setter Property="Background" TargetName="bdCell" Value="{DynamicResource Brush_PA_CSW_DataGridItemDefaultHighlight}"/>                                </DataTrigger>                                <MultiDataTrigger>                                    <MultiDataTrigger.Conditions>                                        <Condition Binding="{Binding (FrameworkElement.DataContext).CurrentDeletingLevel, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" Value="Study"/>                                        <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />                                    </MultiDataTrigger.Conditions>                                    <Setter Property="Background" TargetName="bdCell" Value="{DynamicResource Brush_PA_CSW_DataGridItemHighlight}"/>                                </MultiDataTrigger>                            </ControlTemplate.Triggers>                        </ControlTemplate>                    </Setter.Value>                </Setter>                <Setter Property="Background" Value="Transparent"/>            </Style>