This is a migrated thread and some comments may be shown as answers.

Selector.IsSelectionActive not working ?

3 Answers 575 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Krijn
Top achievements
Rank 1
Krijn asked on 27 Jul 2009, 12:45 PM
Hi

I noticed that the default RadGridView style does not provide a gray row when a Row is selected but not active; window with both textbox and gridView; select line in gridView; line is blue; activate textbox (click or tab); selected line is still blue.

I tried to modify this behavior inside a GridViewRow style using a Multitrigger but it seems that Selector.IsSelectionActive is always false.

This is my current GridViewRow template : 

   <Style TargetType="{x:Type telerik:GridViewRow}">
           
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type telerik:GridViewRow}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <Border x:Name="SelectionBackground"
                                    Grid.Column="2"
                     Background="{TemplateBinding Background}"
                     MinHeight="{TemplateBinding MinHeight}"
                     BorderBrush="{TemplateBinding BorderBrush}"
                     BorderThickness="{TemplateBinding BorderThickness}"
                     Margin="{TemplateBinding Margin}"
                     Padding="{TemplateBinding Padding}" />

                            <Rectangle x:Name="BackgroundRectangle"
                                       Grid.Column="2" Opacity="0"
                        Fill="{DynamicResource telerik.GridViewRowSelectedBackground}"
                        Stroke="{DynamicResource telerik.GridViewRowSelectedBorderBrush}"
                        StrokeThickness="1" />

                            <telerik:IndicatorPresenter x:Name="PART_IndicatorPresenter" 
                                                        Visibility="{TemplateBinding RowIndicatorVisibility}" Grid.Column="0"
                              Background="{TemplateBinding Background}"
                              BorderBrush="BlueViolet"
                              BorderThickness="1,0,1,1">

                                <Path x:Name="NavigatorIndicator"
          Fill="#FF000000" Stretch="Fill" Width="5" Height="8" Data="M254.5,183.75 L254.5,193.33333 260.75,188.16682 z"
          Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center" />

                            </telerik:IndicatorPresenter>
                            <telerik:IndentPresenter x:Name="PART_IndentPresenter" 
                                                     IndentLevel="{TemplateBinding IndentLevel}"
                                                     Grid.Column="1"
                                                     Background="{TemplateBinding Background}" />
                            <telerik:DataCellsPresenter  Height="Auto"
                                                         x:Name="PART_DataCellsPresenter"
                                                         Grid.Column="2"
                     MinHeight="{TemplateBinding MinHeight}" />

                            <Rectangle Width="Auto" Height="Auto"
                                       x:Name="InvalidBorder"
                                       Margin="0"
                                       Visibility="Collapsed"
                                       Stroke="Red"
                                       StrokeThickness="2"
                                       Grid.Column="0" Grid.ColumnSpan="3" />

                        </Grid>
 
                        <ControlTemplate.Triggers>
                           
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="Selector.IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Fill"
                                        TargetName="BackgroundRectangle"
                                        Value="{DynamicResource telerik.GridViewRowSelectedInactiveBackground}"/>
                                <Setter Property="Stroke"
                                        TargetName="BackgroundRectangle"
                                        Value="{DynamicResource telerik.GridViewRowSelectedInactiveBorderBrush}"/>
                            </MultiTrigger>

                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Opacity" TargetName="BackgroundRectangle" Value="1"/>
                            </Trigger>
                           
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" TargetName="SelectionBackground" Value="{DynamicResource telerik.GridViewRowMouseOverBackgroundBrush}"/>
                            </Trigger>
                           
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="False" />
                                    <Condition Property="IsMouseOver" Value="True" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Opacity" TargetName="BackgroundRectangle" Value=".5"/>
                            </MultiTrigger>
                           
                            <Trigger Property="IsCurrent" Value="True">
                                <Setter TargetName="NavigatorIndicator" Property="Visibility" Value="Visible" />
                            </Trigger>
                           
                            <Trigger Property="IsContentValid" Value="False">
                                <Setter TargetName="InvalidBorder" Property="Visibility" Value="Visible" />
                            </Trigger>
                           
                        </ControlTemplate.Triggers>
                       
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="BorderBrush" Value="{DynamicResource telerik.GridViewRowBorderBrush}" />
            <Setter Property="BorderThickness" Value="0,0,0,0" />
            <Setter Property="Margin" Value="0" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="MinHeight" Value="18" />
            <Setter Property="FontSize" Value="11" />
            <Setter Property="FontFamily" Value="Verdana" />
            <Setter Property="FontWeight" Value="Normal" />
            <Setter Property="Foreground" Value="#FF000000" />

             <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=IsAlternating, RelativeSource={RelativeSource Self}}" Value="true"/>
                        <Condition Binding="{Binding Path=UseAlternateRowStyle, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type telerik:RadGridView}}}" Value="true"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource telerik.GridViewRowAlternatingRowBackground}" />
                </MultiDataTrigger>
            </Style.Triggers>

        </Style>

Do you have any idea how to solve this ?

3 Answers, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 28 Jul 2009, 02:58 PM
Hi Krijn,

Please find attached a sample application which shows the selected row when the grid is disabled. Note that the sample uses binaries from our latest internal build which you should be able to download from your user account.

Sincerely yours,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Krijn
Top achievements
Rank 1
answered on 28 Jul 2009, 05:02 PM
Sorry I wasn't more clear but it has nothing to do with Enabled/Disabled functionality.

The WPF property Selector.IsSelectionActive is true when a ListItem inside a ItemsControl is both Selected AND has Keyboard Focus.

The default Style for a ListView uses the IsSelectionActive property inside a style Trigger for setting the BackGround color of the selected row to the selection brush background (aero blue, ...)

When the ItemsControl (=RadGridView) does not have Keyboard focus the SelectedItem is still available, this is presented mostly in gray, see TreeView, ListView, Windows Explorer, ...

Detailed steps:

1. Override MainWindow.xaml (230400-disabled-and-selected-row.zip) content with :

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    x:Class="_30400_Disabled_and_Selected_Row.MainWindow" 
    x:Name="Window" 
    Title="MainWindow" 
    Width="640" Height="480"
    <Grid x:Name="LayoutRoot"
         
         
        <Grid.RowDefinitions> 
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
         
        <TextBox Width="250"/> 
         
        <telerik:RadGridView x:Name="RadGridView1"  
                             Grid.Row="1" 
                             ItemsSource="{Binding Collection, Source={StaticResource SampleDataSource}}"/> 
         
    </Grid> 
</Window> 

2. Run
3. Select some row
4. Set Keyboard focus inside the TextBox
5. Selection Row color is still the 'Active selection color' and not gray

0
Kalin Milanov
Telerik team
answered on 31 Jul 2009, 08:15 AM
Hello Krijn,

Thank you for the detailed clarification. Unfortunately the grid currently does not support this behavior. We recongnize it as native for desktop applications and we will be looking for implementing it in an upcoming release.

I apologize for any inconvenience this might cause and thank yo once more for the great feedback.

Greetings,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Krijn
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Krijn
Top achievements
Rank 1
Share this question
or