DataGridStyle

<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

时间: 2024-10-18 23:47:05

DataGridStyle的相关文章

进行手持设备wince开发中DataGrid的样式设置(宽度)

private void SelectGoodsForm_Load(object sender, EventArgs e) { //定义 DataGrid样式 DataGridTableStyle dataGridStyle = null; dataGridStyle = new DataGridTableStyle(); this.goodsGrid.DataSource = createDataTable(); //清楚之前的DataGrid样式 this.goodsGrid.TableSt

WPF常用控件总结及其应用demo

WPF常用控件总结及其应用 一.控件 1.WrapPanel布局控件:可以实现当空间不足时子控件自动往下一行布局,空间充足时又会自动调整行布局.常用布局控件还有StackPanel(设置其子元素是垂直排列还是水平排列).Grid(通过定义行和列来绘制出一个表格).Canvas(通过指定相对于其的坐标来指定子控件的位置).DockPanel(设置其子元素如何停靠,DockPanel.Left.DockPanel.Right.DockPanel.Top.DockPanel.Bottom). 2.Sc