首页 > 其他 > 详细

DataGridStyle

时间:2014-07-18 12:15:47      阅读:412      评论:0      收藏:0      [点我收藏+]


    <LinearGradientBrush x:Key="VerticalScrollBarBackground" StartPoint="0,0" EndPoint="1,0">
        <GradientStop Offset="0" Color="#FF484C51" />
        <GradientStop Offset="0.20" Color="#FF3F4449" />
        <GradientStop Offset="0.80" Color="#FF46474B" />
        <GradientStop Offset="1" Color="#FF4F5255" />
    </LinearGradientBrush>


    <Style TargetType="DataGrid">
        <Setter Property="AutoGenerateColumns" Value="False" />
        <Setter Property="IsReadOnly" Value="True" />
        <Setter Property="AlternationCount" Value="2" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="{StaticResource VerticalScrollBarBackground}" />
        <Setter Property="GridLinesVisibility" Value="None" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGrid}">           
                    <ContentPresenter></ContentPresenter>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--标题栏样式-->
    <Style TargetType="DataGridColumnHeader">
        <Setter Property="BorderThickness" Value="0"></Setter>
        <Setter Property="Background" Value="#828282"></Setter>
        <Setter Property="Foreground" Value="#000000"></Setter>
        <Setter  Property="Height" Value="24"></Setter>
        <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
        <!--<Setter  Property="FontWeight" Value="Black"></Setter>-->
        <!--<Setter Property="SnapsToDevicePixels" Value="True" />-->
        <!--<Setter Property="Cursor" Value="Hand" />-->
        <!--<Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridColumnHeader">
                    <Border x:Name="BackgroundBorder" BorderThickness="0,1,0,1" BorderBrush="{x:Null}" Width="Auto">
                        <Grid >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0" VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                            <Rectangle Width="1" Fill="Gray" HorizontalAlignment="Right" Grid.ColumnSpan="1" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>-->
    </Style>

    <!--行样式触发-->
    <!--背景色改变必须先设置cellStyle 因为cellStyle会覆盖rowStyle样式-->
    <!--隔行换色-->
    <Style  TargetType="DataGridRow">
        <Setter Property="BorderThickness" Value="0"></Setter>
        <Setter  Property="Height" Value="24"></Setter>
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                <Setter Property="Background" Value="#333333"></Setter>
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                <Setter Property="Background" Value="#424242"></Setter>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="White"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!--单元格样式触发-->
    <!--目前使用覆盖掉默认的IsSelected-->
    <Style TargetType="DataGridCell">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="BorderThickness" Value="0"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="dataGridTextColumnStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="HorizontalAlignment" Value="Center"></Setter>
        <Setter Property="VerticalAlignment" Value="Center"></Setter>
        <Setter Property="Foreground" Value="#999999"></Setter>
    </Style>

    <Style TargetType="{x:Type DataGridRowHeader}">
        <Setter Property="Width" Value="0"></Setter>
    </Style>

DataGridStyle,布布扣,bubuko.com

DataGridStyle

原文:http://www.cnblogs.com/hidden/p/3852973.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!