开发者

setting rowstyle in datagrid, silverlight 4

I am trying to change the rowstyle for a datagrid to change the background color when a row is selected(not the row background but the color of the selec开发者_如何学Ction rectangle, which by default is a bit too shiny for my application). However the behaviour i'm seeing on applying to style to the grid is that all the rows are getting shrinked together like a folded venetian blind. This is the style that i have written:

<Style x:Key="DataGridRowStyle" TargetType="sdk:DataGridRow">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="sdk:DataGridRow">
                        <sdk:DataGrid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">                                       
                                    <VisualState x:Name="Normal Selected">
                                        <Storyboard>
                                            <ColorAnimation 
                                                Storyboard.TargetName="ButtonBrush" 
                                                Storyboard.TargetProperty="Color" 
                                                To="Red" />                                            
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </sdk:DataGrid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Can someone tell me what's going on here? tbh I havn't really understood how the visual states work and kind of just shooting in the dark.

Thanks


Checking the template for the DataGrid (check here) the background color (that blue) is hard coded in the template. When the row is selected all that happens is that a rectangle becomes visible (Opacity=1). Sadly have to say that you have to re-template the whole DataGridRow... in the provided link you'll find all you might need for this.

In the template look for some code like this: <Rectangle x:Name="BackgroundRectangle" Grid.RowSpan="2" Grid.ColumnSpan="2" Opacity="0" Fill="#FFBADDE9"/>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜