none
弱智问题一个:如何改变DataGridView选中行、鼠标悬浮行的样式。 RRS feed

  • 问题

  • 弱智问题一个:如何改变DataGridView选择行、鼠标悬浮行的样式。
    我的意思是,当选择某行时,或者鼠标悬浮在某个行的时候,希望能用特定的背景颜色(最好是半透明的颜色,因为我的行都有特定的颜色,当选择某个行后者鼠标悬浮在某个行时,它把我原来的颜色改变了),有无办法改变?

    2009年10月12日 3:52

答案

  • 超过字数了,接上帖:

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

     

     

    <Storyboard>

     

     

    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Visibility">

     

     

    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>

     

     

    </ObjectAnimationUsingKeyFrames>

     

     

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

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

    </vsm:VisualStateGroup>

     

     

    </vsm:VisualStateManager.VisualStateGroups>

     

     

    <Grid.RowDefinitions>

     

     

    <RowDefinition/>

     

     

    <RowDefinition Height="Auto"/>

     

     

    <RowDefinition Height="Auto"/>

     

     

    </Grid.RowDefinitions>

     

     

    <Grid.ColumnDefinitions>

     

     

    <ColumnDefinition Width="Auto" />

     

     

    <ColumnDefinition/>

     

     

    </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="Orange"/>

     

     

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

     

     

    <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>

     

     

     

    </

    UserControl>

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.
    2009年10月13日 8:05
    版主

全部回复

  • 我问的silverlight的DataGrid。
    ASP.NET+AJAX的那种我不玩了。我觉得SL才是以后BS胖客户端的发展前景。
    2009年10月12日 6:00
  • 你好,
    可以自定义RowStyle:
    使用:

     

    <data:DataGrid RowStyle="{StaticResource DataGridRowStyle}" ..

    定义:

    <

     

    <data:DataGrid RowStyle="{StaticResource DataGridRowStyle}" ..

    定义:

    <

    <data:DataGrid RowStyle="{StaticResource DataGridRowStyle}" ..

    定义:

    <

     

    UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SilverlightApplication9.MainPage"

     

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     

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

     

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

     

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008">

    <
    UserControl.Resources>

     

     

    <Style x:Key="DataGridRowStyle" TargetType="data:DataGridRow">

     

     

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

     

     

    <Setter Property="Template">

     

     

    <Setter.Value>

     

     

    <ControlTemplate TargetType="data:DataGridRow">

     

     

    <localprimitives:DataGridFrozenGrid Name="Root">

     

     

    <vsm:VisualStateManager.VisualStateGroups>

     

     

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

     

     

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

     

     

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

     

     

    <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=".5"/>

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

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

     

     

    <Storyboard>

     

     

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

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

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

     

     

    <Storyboard>

     

     

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

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

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

     

     

    <Storyboard>

     

     

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

     

     

    <ColorAnimation Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="(Fill).Color" To="#FFE1E7EC"/>

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

    </vsm:VisualStateGroup>

     

     

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

     

     

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


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.
    2009年10月13日 8:05
    版主
  • 超过字数了,接上帖:

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

     

     

    <Storyboard>

     

     

    <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Visibility">

     

     

    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>

     

     

    </ObjectAnimationUsingKeyFrames>

     

     

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

     

     

    </Storyboard>

     

     

    </vsm:VisualState>

     

     

    </vsm:VisualStateGroup>

     

     

    </vsm:VisualStateManager.VisualStateGroups>

     

     

    <Grid.RowDefinitions>

     

     

    <RowDefinition/>

     

     

    <RowDefinition Height="Auto"/>

     

     

    <RowDefinition Height="Auto"/>

     

     

    </Grid.RowDefinitions>

     

     

    <Grid.ColumnDefinitions>

     

     

    <ColumnDefinition Width="Auto" />

     

     

    <ColumnDefinition/>

     

     

    </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="Orange"/>

     

     

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

     

     

    <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>

     

     

     

    </

    UserControl>

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.
    2009年10月13日 8:05
    版主