Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Datagrid Selected Row Color RSS

2 replies

Last post Aug 23, 2011 11:50 AM by asimsajjad

(0)
  • vss712

    vss712

    Member

    102 Points

    135 Posts

    Datagrid Selected Row Color

    Aug 22, 2011 07:21 PM | LINK

    Hello,

    What is the property for the Datagrid selected row color, and can someone tell me how to change the color and reset the color via code?

     

    THank you

  • doubler_137

    doubler_137

    Member

    67 Points

    11 Posts

    Re: Datagrid Selected Row Color

    Aug 23, 2011 11:47 AM | LINK

    hope this may help

    <data:DataGrid x:Name="grid">
        <data:DataGrid.ColumnHeaderStyle>
            <Style 
                xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data" 
                xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
                TargetType="primitives:DataGridColumnHeader" >
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="primitives:DataGridColumnHeader">
                            <Grid Name="Root">
                                <vsm:VisualStateManager.VisualStateGroups>
                                    <vsm:VisualStateGroup x:Name="SortStates" >
                                        <vsm:VisualStateGroup.Transitions>
                                            <vsm:VisualTransition GeneratedDuration="00:00:0.1" />
                                        </vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualState x:Name="Unsorted" />
                                        <vsm:VisualState x:Name="SortAscending">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                        <vsm:VisualState x:Name="SortDescending">
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="SortIcon" Storyboard.TargetProperty="Opacity" Duration="0" To="1.0" />
                                                <DoubleAnimation Storyboard.TargetName="SortIconTransform" Storyboard.TargetProperty="ScaleY" Duration="0" To="-.9" />
                                            </Storyboard>
                                        </vsm:VisualState>
                                    </vsm:VisualStateGroup>
                                </vsm:VisualStateManager.VisualStateGroups>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Rectangle x:Name="BackgroundRectangle" Stretch="Fill" Fill="LightBlue" Grid.ColumnSpan="2" Grid.RowSpan="2"  />
                                <ContentPresenter Grid.RowSpan="2" Content="{TemplateBinding Content}" Cursor="{TemplateBinding Cursor}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" />
                                <Rectangle Name="VerticalSeparator" Grid.RowSpan="2" Grid.Column="2" Width="1" VerticalAlignment="Stretch" Fill="{TemplateBinding SeparatorBrush}" Visibility="{TemplateBinding SeparatorVisibility}" />
                                <Path Grid.RowSpan="2" Name="SortIcon" RenderTransformOrigin=".5,.5" HorizontalAlignment="Left" VerticalAlignment="Center" Opacity="0" Grid.Column="1" Stretch="Uniform" Width="8" Data="F1 M -5.215,6.099L 5.215,6.099L 0,0L -5.215,6.099 Z ">
                                    <Path.Fill>
                                        <SolidColorBrush Color="#FF444444" />
                                    </Path.Fill>
                                    <Path.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform x:Name="SortIconTransform" ScaleX=".9" ScaleY=".9"  />
                                        </TransformGroup>
                                    </Path.RenderTransform>
                                </Path>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </data:DataGrid.ColumnHeaderStyle>
    </data:DataGrid>
    
  • asimsajjad

    asimsajjad

    Star

    8200 Points

    1771 Posts

    Re: Datagrid Selected Row Color

    Aug 23, 2011 11:50 AM | LINK

    Here are the similar post which may help you

    http://forums.silverlight.net/p/12562/41797.aspx

     

    do you want to change color at run time or just want to change default selected color of the row ?

     

    Asim Sajjad
    http://asimsajjad.blogspot.com
    Twitter: http://twitter.com/asimsajjad
    If this has answered your question, please click on "mark as answer" on this post. Thank you!