首页 > 其他分享 >wpf datagrid row background color alternatively changed based on row index,AlternationConverter,Alte

wpf datagrid row background color alternatively changed based on row index,AlternationConverter,Alte

时间:2024-03-12 17:26:38浏览次数:16  
标签:index based AlternationConverter color AlternationCount row

<Window x:Class="WpfApp7.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp7"
        mc:Ignorable="d" WindowState="Maximized" WindowStartupLocation="CenterOwner"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.Resources>
            <AlternationConverter x:Key="rowBgColor">
                <SolidColorBrush>Red</SolidColorBrush>
                <SolidColorBrush>Blue</SolidColorBrush>
                <SolidColorBrush>Green</SolidColorBrush>
                <SolidColorBrush>Orange</SolidColorBrush>
            </AlternationConverter>
            <Style x:Key="dgRowStyle" TargetType="{x:Type DataGridRow}">
                <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource self},
                    Path=(ItemsControl.AlternationIndex),Converter={StaticResource rowBgColor }}"></Setter>
            </Style>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <DataGrid x:Name="mainDG" Grid.Row="0" VirtualizingPanel.IsContainerVirtualizable="True" VirtualizingPanel.IsVirtualizing="True"
                      EnableColumnVirtualization="True" EnableRowVirtualization="True" 
                      VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingPanel.VirtualizationMode="Recycling"
                    AlternationCount="4"  RowStyle="{StaticResource dgRowStyle}" >            
        </DataGrid>
        <Button Content="Load Data" Click="Button_Click" Grid.Row="1"/>
    </Grid>
</Window>

 

 

标签:index,based,AlternationConverter,color,AlternationCount,row
From: https://www.cnblogs.com/Fred1987/p/18068771

相关文章

  • lightdb 支持 timestamp_to_scn 和 ora_rowscn
    背景Oracle的timestamp_to_scn函数能根据时间戳返回一个SCN(SystemChangeNumber).scn与事务有关,当系统有事务提交后,最新的scn就会变更成一个更大的值。ORA_ROWSCN在Oracle中记录了每一行提交后的scn.在LightDB中,scn被替换成xid,即事务ID.样例在LightDB......
  • [Rust] Thread 3: move keyword to resolve borrowing problem for closure
    Weofteruse movewithclosurespassedto thread::spawnbecasetheclosurewillthentakeownershipofthevaluesitusesfromtheenvironment,thustransferringowershopofthosevaluesfromonethreadtoanother. Thefollowingcodewon'twork:use......
  • 关于Pyinstaller在打包Streamlit程序时遇到的IndexError:tuple index out of range
    如题,在使用Pyinstaller库打包过程中,如果遇到IndexError:tupleindexoutofrange,不必惊慌,本质上是库函数在传参过程中出现异常下面是解决方案:找到..\envs\steamlit\lib\dis.py这个文件。如果你是用的虚拟环境,比如conda,那这个文件位于anaconda的安装目录"E:\SOFTWARE\ANAC......
  • 遥感图像镶嵌拼接:ENVI的Pixel Based Mosaicking工具操作方法
      本文介绍基于ENVI软件,利用“PixelBasedMosaicking”工具实现栅格遥感影像镶嵌拼接的方法。  首先需要说明的是,本文需要镶嵌的遥感影像并不含地理参考信息,因此仅可以使用ENVI中的“PixelBasedMosaicking”工具(该工具可以对含有或不含有地理参考信息的图像进行镶嵌),而不是......
  • Pacing guide is based on five 50 minute class sessions per week
    Pacingguideisbasedonfive50minuteclasssessionsperweekcorecontent     corecontent     capstone     explorations     optionalcontent     WEEK1 Session1Session2Session......
  • SQLIntegrityConstraintViolationException: Cannot add or update a child row: a fo
    异常原因:两张表存在外键关联并且有级联操作,级联更新或级联删除等1.(此处为)设置的外键与另一个表中的唯一索引列(一般是主键)中的值不匹配2.添加的外键列与另一个表的唯一索引列(一般是主键)的数据类型不同......
  • @Indexed
    假设你有一个服务类,你希望Spring在启动时能够快速地识别并注册它:importorg.springframework.stereotype.Indexed;importorg.springframework.stereotype.Service;@Indexed@ServicepublicclassMyService{   //类的实现}在这个例子中,@Service注解标记这个类为一个服务组......
  • Kibana8.0怎么添加索引index至discover
    ELK7版本索引输入至elasticsearch后使用CreateIndexpattern添加索引至Kibana在ELK8版本添加方式有所不同左侧菜单选择Management选择Kibana-DataViews创建dataview查看Discover选择刚刚设置的索引名即可......
  • Blazor笔记-Browser storage
    更新记录注意:非教程。纯笔记,日常查询用的。需要教程的小伙伴找几本书看看即可哈哈,有Vue基础的话非常快,概念都是通的。非工作需要不建议深入学习Blazor,深入Vue吧,用的多,哈哈。完整目录地址:https://www.cnblogs.com/cqpanda/p/17596348.html点击查看2024年3月7日发布。2023......
  • VUE通过for循环一行显示多列el-row
    效果图: 代码: <template><el-row:gutter="0"v-for="(item,index)inarrLen":key="item.name"style="height:200px">......