首页 > 编程语言 >C# WPF ListView 改变某行某列的背景颜色

C# WPF ListView 改变某行某列的背景颜色

时间:2023-02-16 07:44:04浏览次数:39  
标签:set 某列 get C# ITEMS new WPF public string

通过前端绑定Background属性实现,代码如下:

<ListView x:Name="listView1" ItemsSource="{Binding items}" Width="641" Margin="0,0,0,-5"   ItemContainerStyle="{StaticResource ListViewItemStyle}">
     <ListView.View>
         <GridView>
              <GridViewColumn Header="     序号" Width="130">
	              <GridViewColumn.CellTemplate>
                      <DataTemplate>
                          <TextBlock Width="110" TextAlignment="Center" Background="{Binding numberBackgroud}" Text="{Binding number}"></TextBlock>
                      </DataTemplate>
                  </GridViewColumn.CellTemplate>
              </GridViewColumn>
              <GridViewColumn Header="     名称" Width="110">
              	<GridViewColumn.CellTemplate>
                      <DataTemplate>
                          <TextBlock Width="110" TextAlignment="Center" Background="{Binding nameBackgroud}" Text="{Binding name}"></TextBlock>
                      </DataTemplate>
                  </GridViewColumn.CellTemplate>
              </GridViewColumn>
          </GridView>
      </ListView.View>
  </ListView>
        public class DataClass
        {
            public string number { get; set; }
            public string numberBackground { get; set; }
            public string name { get; set; }
            public string nameBackground { get; set; }
        }

	   List<ListViewItem> ITEMS = new List<ListViewItem>();
       // 资源绑定
	   listView1.ItemsSource = ITEMS;
	   ListViewItem one_item = new ListViewItem();
	   one_item.Content = new DataClass()
	   {
	       number = "11",
	       name = "hello_world",
	       numberBackground = "red",
	       nameBackground = "Yellow",
	
	   };
	   ITEMS.Add(one_item);

标签:set,某列,get,C#,ITEMS,new,WPF,public,string
From: https://www.cnblogs.com/guangzhiruijie/p/17125360.html

相关文章

  • 本地存储Cookies 的获取和存入 - js-Cookies
    //导入js-cookie用于操作cookieimportCookiesfrom"js-cookie";constTokenKey="hrsass_admin_token";constLoginKey="hrsass_login_time";//读取tokenex......
  • ABC222H 题解
    很久之前我问joke3579有没有什么水黑,然后他给我了这个题。小推一波。题解看到这种东西首先找找有没有什么性质。简单分析可以得出一棵美丽的\(n\)阶二叉树一定满足如......
  • react-创建和基本使用
    1.新建空文件夹2.在vscode里打开这个文件夹3.新建html文件和一个resource包4,。导入3个文件5.引入js文件     ......
  • AcWing 785.快速排序(Java)
    题目描述给定你一个长度为n的整数数列。请你使用快速排序对这个数列按照从小到大进行排序。并将排好序的数列按顺序输出。输入格式输入共两行,第一行包含整数n。第......
  • metamask 所有官方版最新版下载,chrome浏览器插件, 区块链以太坊eth钱包安装使用教程
    在区块链技术日益发展的今天,数字货币的使用也越来越广泛。作为数字货币的一种存储和交易方式,钱包在数字货币领域也扮演着重要的角色。在这其中,MetaMask是一种功能强大的钱......
  • C#快速入门 _笔记
      https://www.youtube.com/watch?v=Mz-8PpvflaQ&list=PLJgD_fXVXZKppT4stJ09s9nu3byvyMERE&index=20 20.访问修饰符private:私有的,仅类的内部可以访问protected:......
  • LC 384. Shuffle an Array
    384.ShuffleanArray思路与题解按照post[1]中的解释,这么想这个问题:第一次抽牌中,\(k\)没被抽中的概率为:\[P(A_{1}\neqk)=\frac{n-1}{n}\]第二次抽牌,\(k\)被抽......
  • 解决mysqlclient安装报缺少Microsoft Visual C++ 14.0 is required
    安装mysqlclient报错error:MicrosoftVisualC++14.0isrequired.Getitwith“MicrosoftVisualC++BuildTools”1.不要去下载VisualStudio!!!==没什么用(对我而言)......
  • LC 2447. Number of Subarrays With GCD Equal to K
    2447.NumberofSubarraysWithGCDEqualtoK思路与题解最大公约数,Euclideanalgorithms算法证明:如果我们有2个数:\(a\)和\(b\),不妨假设\(a>b\),当不能整除的情......
  • [LeetCode] 2341. Maximum Number of Pairs in Array
    Youaregivena 0-indexed integerarray nums.Inoneoperation,youmaydothefollowing:Choose two integersin nums thatare equal.Removebothinte......