zoukankan      html  css  js  c++  java
  • WPF中的实现类似Excel的动态条件格式

      条件格式是Excel一个非常常见的功能,所谓动态条件格式,也就是根据数据库的内容,动态的为每个单元格设置格式样式而已。本文主要讨论如何在WPF的网格应用程序中开发实现这一功能。ComponentOne Studio for WPF中的网格控件C1FlexGrid有一个叫CellFactory的类,CellFactory类允许在单元格中自定义网格,接下来就主要用到这个类来实现动态条件格式的效果。

    ComponentOne如何实现WPF中的动态条件格式

    首先,创建一个继承于CellFactory类的类。

    public class CustomCellFactory : CellFactory
    {
      
    }

    然后用CellFactory类来覆盖CreateCellContent()方法,用条件来设置单元式的边框元素的背景。

    public override void CreateCellContent(C1FlexGrid grid, Border bdr, CellRange rng)
    {
       base.CreateCellContent(grid, bdr, rng);
       //format cells in second column
       if (rng.Column == 2)
       {
          if (grid[rng.Row, rng.Column].ToString() == "Japan")
          {
             bdr.Background = new SolidColorBrush(Colors.LimeGreen);
          }
          else if (grid[rng.Row, rng.Column].ToString() == "India")
          {
             bdr.Background = new SolidColorBrush(Colors.MediumVioletRed);
          }
          else if (grid[rng.Row, rng.Column].ToString() == "United States")
          {
             bdr.Background = new SolidColorBrush(Colors.Yellow);
          }
          else if (grid[rng.Row, rng.Column].ToString() == "United Kingdom")
          {
             bdr.Background = new SolidColorBrush(Colors.Gold);
          }
       }
    }

    然后动态条件格式就完成了,下面这个GIF就是其动态效果:

    ComponentOne如何实现WPF中的动态条件格式

  • 相关阅读:
    通过jsonp解决ajax的跨域请求问题
    为php安装redis扩展模块并测试
    浅谈使用 PHP 进行手机 APP 开发(API 接口开发)(转)
    touch事件记录
    jquery mobile 问题
    background总结,转自http://www.daqianduan.com/3302.html
    博客收集
    css3 border-radius 总结
    css3 box-shadow 总结
    angular 重置表单
  • 原文地址:https://www.cnblogs.com/uncleshu/p/3213708.html
Copyright © 2011-2022 走看看