Datagrid布局与样式(居中,单元格颜色,排序)

在这里插入图片描述

<Page x:Class="Lx.Pages.Page_bkzj_gn"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:Lx.Pages"
      xmlns:c="clr-namespace:Lx.Converters"
      xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="Page_bkzj_gn">


    <Page.Resources>
        <c:NumConverter x:Key="NumConverter"/>
        <c:MyColorConverter x:Key="colorConverter"/>

        <Style TargetType="RadioButton">
            <Setter Property="Margin" Value="5"></Setter>
            <Setter Property="Command"  Value="{Binding CheckChangedCommand}" ></Setter>
            <Setter Property="CommandParameter" Value="{Binding  RelativeSource={RelativeSource Mode=Self}}"/>
        </Style>
      
        
        <!-- DataGridTextColumn 文字居中 -->
        <Style x:Key="CenterAlignmentStyle" TargetType="TextBlock">
            <Setter Property="TextAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
        </Style>
        
        <!--CollectionViewSource-->
        <CollectionViewSource x:Key="cvsTasks" Source="{Binding Path=DataList}" >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="f62" Direction="Descending"/>
                <scm:SortDescription PropertyName="f3" Direction="Descending"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <!--<Style TargetType="DataGridCell">
            <Setter Property="Foreground"
                    Value="{Binding Path=Item.PropertyPath, RelativeSource={RelativeSource Mode=Self},Converter={StaticResource colorConverter}}"/>
        </Style>-->

    </Page.Resources>
    
    <DockPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" >
            <RadioButton  x:Name="rad1" IsChecked="True"   >今日</RadioButton>
            <RadioButton  x:Name="rad2" IsChecked="False">5日</RadioButton>
            <RadioButton  x:Name="rad3" IsChecked="False">10日</RadioButton>
        </StackPanel>

        <DataGrid ItemsSource="{Binding Source={StaticResource cvsTasks}}" CanUserAddRows="False" AutoGenerateColumns="False">
            <DataGrid.Columns >
                <DataGridTextColumn Header="名称" Binding="{Binding f14}"  ElementStyle="{StaticResource CenterAlignmentStyle}"/>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日跌涨幅" 
                    Binding="{Binding f3, Converter={StaticResource NumConverter},
                                     ConverterParameter=100, StringFormat={}{0:P2}}" >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f3, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                    
                    
                </DataGridTextColumn>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日主力净流入" Binding="{Binding f62, Converter={StaticResource NumConverter},
                    ConverterParameter=100000000, StringFormat={}{0:0.00}亿}" >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f62, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn> 

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="净占比"    Binding="{Binding f184, Converter={StaticResource NumConverter},
                    ConverterParameter=100, StringFormat={}{0:P2}}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f184, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>


                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日超大单流入"    Binding="{Binding f66, Converter={StaticResource NumConverter},
                    ConverterParameter=100000000, StringFormat={}{0:0.00}亿}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f66, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
                
                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="净占比" 
                    Binding="{Binding f69, Converter={StaticResource NumConverter},
                    ConverterParameter=100, StringFormat={}{0:P2}}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f69, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>


                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日大单净流入"      
                    Binding="{Binding f72, Converter={StaticResource NumConverter},
                    ConverterParameter=100000000, StringFormat={}{0:0.00}亿}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f72, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="净占比"        
                    Binding="{Binding f75, Converter={StaticResource NumConverter},
                    ConverterParameter=100, StringFormat={}{0:P2}}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f75, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日中单净流入"         
                    Binding="{Binding f78, Converter={StaticResource NumConverter},
                    ConverterParameter=100000000, StringFormat={}{0:0.00}亿}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f78, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="净占比"        
                    Binding="{Binding f81, Converter={StaticResource NumConverter},
                    ConverterParameter=100, StringFormat={}{0:P2}}" >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f81, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>


                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="今日小单净流入"       
                    Binding="{Binding f84, Converter={StaticResource NumConverter},
                    ConverterParameter=100000000, StringFormat={}{0:0.00}亿}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f84, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>

                <DataGridTextColumn  ElementStyle="{StaticResource CenterAlignmentStyle}"
                    Header="净占比"         
                    Binding="{Binding f87, Converter={StaticResource NumConverter},ConverterParameter=100, StringFormat={}{0:P2}}"  >
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Foreground" Value="{Binding f87, Converter={StaticResource colorConverter}}"/>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</Page>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值