Skip to main content

Microsoft Silverlight

Answered Question Turn off or change color of datagrid Mouse Hover effectRSS Feed

(0)

imohamed
imohamed

Member

Member

9 points

27 Posts

Turn off or change color of datagrid Mouse Hover effect

Is there a way I can turn off or change the color of the mouse over hover effect in datagrid? Thanks

GuinnessKMF
GuinnessKMF

Member

Member

222 points

58 Posts

Re: Turn off or change color of datagrid Mouse Hover effect

The DataGrid Styles and Templates (http://msdn.microsoft.com/en-us/library/cc278066(vs.95).aspx) contains the information you need to change control behavior that is not exposed by a public property.

 By changing the style of the DataGridRows of your DataGrid you can recreate the template with a different "BackgroundRectangle" Fill, or you can change the MouseOver storyboard to not adjust the opacity of that rectangle.

-Kellen

GuinnessKMF
GuinnessKMF

Member

Member

222 points

58 Posts

Answered Question

Re: Re: Turn off or change color of datagrid Mouse Hover effect

So if what I said wasn't clear enough.  You want to create a staticResource that is a style that's an exact copy of the DataGridRow from the link.  Then you want to change that style to meet your needs (setting opacity to 0 for the mouseover to property, or changing the color of the BackgroundRectangle), and then set the style of your DataGrid's RowStyle to {StaticResource KeyOfStyle}.

<UserControl x:Class="YourControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows"

xmlns:localprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"

>

<UserControl.Resources>

<Style x:Key="NoHoverStyle" TargetType="local:DataGridRow">

<Setter Property="IsTabStop" Value="False" />

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="local:DataGridRow">

<localprimitives:DataGridFrozenGrid Name="Root">

<vsm:VisualStateManager.VisualStateGroups>

<vsm:VisualStateGroup x:Name="CommonStates">

<vsm:VisualStateGroup.Transitions>

<vsm:VisualTransition GeneratedDuration="0" />

</vsm:VisualStateGroup.Transitions>

<vsm:VisualState x:Name="Normal" />

<vsm:VisualState x:Name="Normal AlternatingRow">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="0"/>

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="MouseOver">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="0"/>

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="Normal Selected">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/>

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="MouseOver Selected">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/>

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="Unfocused Selected">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="1"/>

<ColorAnimationUsingKeyFrames BeginTime="0" Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">

<SplineColorKeyFrame KeyTime="0" Value="#FFE1E7EC"/>

</ColorAnimationUsingKeyFrames>

</Storyboard>

</vsm:VisualState>

</vsm:VisualStateGroup>

</vsm:VisualStateManager.VisualStateGroups>

<Grid.RowDefinitions>

<RowDefinition Height="*"/>

<RowDefinition Height="Auto"/>

<RowDefinition Height="Auto"/>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="Auto" />

<ColumnDefinition Width="*" />

</Grid.ColumnDefinitions>

<Grid.Resources>

<Storyboard x:Key="DetailsVisibleTransition">

<DoubleAnimation Storyboard.TargetName="DetailsPresenter" Storyboard.TargetProperty="ContentHeight" Duration="00:00:0.1" />

</Storyboard>

</Grid.Resources>

<Rectangle x:Name="BackgroundRectangle" Grid.RowSpan="2" Grid.ColumnSpan="2" Opacity="0" Fill="#FFBADDE9"/>

<localprimitives:DataGridRowHeader Grid.RowSpan="3" Name="RowHeader" localprimitives:DataGridFrozenGrid.IsFrozen="True" />

<localprimitives:DataGridCellsPresenter Grid.Column="1" Name="CellsPresenter" localprimitives:DataGridFrozenGrid.IsFrozen="True" />

<localprimitives:DataGridDetailsPresenter Grid.Row="1" Grid.Column="1" Name="DetailsPresenter" />

<Rectangle Grid.Row="2" Grid.Column="1" Name="BottomGridLine" HorizontalAlignment="Stretch" Height="1" />

</localprimitives:DataGridFrozenGrid>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</UserControl.Resources>

<Grid x:Name="LayoutRoot" >
<local:DataGrid RowStyle="{StaticResource NoHoverStyle}" > ... </local:DataGrid>
</Grid>
</
UserControl>

-Kellen

imohamed
imohamed

Member

Member

9 points

27 Posts

Re: Re: Turn off or change color of datagrid Mouse Hover effect

Kellen

You are great!!!   I got it working just by copy and paste your code and made small changes!!! You are awsome.. thanks..

I have one other problem.  The fist cell (row=0, collumn=0) is shown as selected when the grid is loaded.  Where do I turn off that effect?  I set all the opacity for Selected state to 0.

Thanks

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities