Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
170
Trying to get the underlying data when I hover over a row
posted

I have a XamGrid and I want to be able to get the underlying row info when I hover over the row.  I have the rows change background color when there is a mouse move over a row.  Here is the xaml for that piece:

<UserControl.Resources>

        <SolidColorBrush x:Key="CellItemSelectedBorderBrush" Color="#FF6DBDD1"/>

        <SolidColorBrush x:Key="CellItemSelectedBackgroundBrush" Color="Yellow"/>

        <SolidColorBrush x:Key="CellItemAltNormalBackgroundBrush" Color="#FFF6F9FC"/>

        <SolidColorBrush x:Key="CellItemNormalBackgroundBrush" Color="#FFFFFFFF"/>

        <SolidColorBrush x:Key="CellItemNormalBorderBrush" Color="#FFC9CACA"/>

        <SolidColorBrush x:Key="CellRowHoverBackgroundBrush" Color="LightBlue"/>

        <SolidColorBrush x:Key="GridRowBackgroundBrush" Color="White"/>

        <Style TargetType="ig:CellControl">

            <Setter Property="FontSize" Value="11" />

            <Setter Property="VerticalContentAlignment" Value="Center" />

            <Setter Property="Background" Value="{StaticResource GridRowBackgroundBrush}"/>

            <Setter Property="BorderBrush" Value="{StaticResource CellItemNormalBorderBrush}"/>

            <Setter Property="BorderThickness" Value="0"/>

            <Setter Property="HorizontalContentAlignment" Value="Left"/>

            <Setter Property="Padding" Value="5"/>

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="ig:CellControl">

                        <Grid>

                            <VisualStateManager.VisualStateGroups>

                                <VisualStateGroup x:Name="CommonStates">

                                    <VisualState x:Name="Normal" />

                                    <VisualState x:Name="MouseOver">

                                        <Storyboard >

                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AltMouseOver" Storyboard.TargetProperty="Fill">

                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellRowHoverBackgroundBrush}"/>

                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>

                                    </VisualState>

                                    <VisualState x:Name="Alternate" >

                                        <Storyboard>

                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="AltMouseOver" Storyboard.TargetProperty="Fill">

                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellItemAltNormalBackgroundBrush}"/>

                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>

                                    </VisualState>

                                </VisualStateGroup>

                                <VisualStateGroup x:Name="SelectedStates">

                                    <VisualState x:Name="NotSelected" />

                                    <VisualState x:Name="Selected">

                                        <Storyboard >

                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="Background">

                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{StaticResource CellItemSelectedBackgroundBrush}"/>

                                            </ObjectAnimationUsingKeyFrames>

                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="BorderThickness">

                                                <DiscreteObjectKeyFrame KeyTime="00:00:00" >

                                                    <DiscreteObjectKeyFrame.Value>

                                                    

                                                        <Thickness>0</Thickness>

                                                    </DiscreteObjectKeyFrame.Value>

                                                </DiscreteObjectKeyFrame>

                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>

                                    </VisualState>

                                </VisualStateGroup>

                                <VisualStateGroup x:Name="ActiveStates">

                                    <VisualState x:Name="InActive" />

                                    <VisualState x:Name="Active">

                                        <Storyboard >

                                            <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00" Storyboard.TargetName="ActiveSelected" Storyboard.TargetProperty="BorderThickness">

                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">

                                                    <DiscreteObjectKeyFrame.Value>

                                                         <Thickness>0</Thickness>

                                                    </DiscreteObjectKeyFrame.Value>

                                                </DiscreteObjectKeyFrame>

                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>

                                    </VisualState>

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>

                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" x:Name="Root"/>

                            <Rectangle x:Name="AltMouseOver" Margin="{TemplateBinding BorderThickness}"/>

                            <Border x:Name="ActiveSelected" BorderBrush="{StaticResource CellItemSelectedBorderBrush}"   ></Border>

                            <ContentPresenter   VerticalAlignment="{TemplateBinding VerticalContentAlignment}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>

                        </Grid>

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

    </UserControl.Resources>

 

The hover works great ( turns the row background to blue ), but I need to know which row the mouse is over so I can get the underlying data.  Thanks for the help.

 

Parents
  • 12875
    posted

    Hi Kathy, 

    You can add a MouseEnter event setter to your CellControl style

    <EventSetter Event="MouseEnter" Handler="CellControl_MouseEnter" /> 

    and then use the cellControl's DataContext to look at the row data.  In my case the row items are defined by a GridData class. 

    void CellControl_MouseEnter(object sender, RoutedEventArgs e)

    {

        CellControl c = sender as CellControl;

        GridData data =  c.DataContext as GridData;

    Hope this helps.  Please let me know if you have any questions.

Reply Children
No Data