Row only selected when clicked directly on text

Nov 25, 2008 at 4:44 PM
Our data grid rows only get selected when we click directly on the actual - when we click on the row but around the text it doesn't get highlighted.  Any ideas why?

    <Style x:Key="14PointTextStyle" BasedOn="{StaticResource BasicTextStyle}">
        <Setter Property="Control.FontSize" Value="14"/>
        <Setter Property="Control.FontFamily" Value="Tahoma"/>
        <Setter Property="Control.Foreground" Value="Black"/>
    </Style>


            <Style x:Key="StudiesListDataGridRowStyle" TargetType="{x:Type dg:DataGridRow}" BasedOn="{StaticResource 14PointTextStyle}">
                <Setter Property="Height" Value="50" />
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Background" >
                    <Setter.Value>
                        <ImageBrush ImageSource="../Resources/Images/Backgrounds/650x50BlueItemBackground.png" Stretch="Fill"/>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="Background" >
                            <Setter.Value>
                                <ImageBrush ImageSource="../Resources/Images/Backgrounds/650x50DarkBlueItemBackground.png" Stretch="Fill"/>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style x:Key="StudiesListDataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="BorderThickness" Value="0" />
                <Setter Property="Height" Value="50" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                            <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="StudiesListDataRowHeaderStyle" TargetType="{x:Type dg:DataGridRowHeader}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type dg:DataGridRowHeader}">
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


        <dg:DataGrid
        AutoGenerateColumns="False"
        x:Name="studiesDataGrid"
        IsReadOnly="True"
        Background="Transparent"
        GridLinesVisibility="None"
        SelectionMode="Single"
        SelectionUnit="FullRow"
        Width="650"
        BorderThickness="0"
        ScrollViewer.VerticalScrollBarVisibility="Hidden"
        ScrollViewer.HorizontalScrollBarVisibility="Hidden"
        RowStyle="{StaticResource StudiesListDataGridRowStyle}"
        CellStyle="{StaticResource StudiesListDataGridCellStyle}"
        RowHeaderStyle="{StaticResource StudiesListDataRowHeaderStyle}"
        RowDetailsVisibilityMode="VisibleWhenSelected"
            > ...

Nov 25, 2008 at 5:10 PM
Hi,

If you re-instate the Border which is in the DataGridCell's original template it fixes the problem:

<Style  x:Key="StudiesListDataGridCellStyle" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Height" Value="50" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type dg:DataGridCell}">
                <Border Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"  
                          BorderThickness="{TemplateBinding BorderThickness}"
                          SnapsToDevicePixels="True">
                    <ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Colin E.
Nov 25, 2008 at 5:15 PM
awesome, thanks Colin.  will remember that in the future.