Silverlight 3中的datagrid contol [英] datagrid contol in silverlight 3

查看:81
本文介绍了Silverlight 3中的datagrid contol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我在Silverlight 3 .net Framework 4.0中有一个datagird包含1到99个数字
我必须根据传递的参数查找单元格数据,并且必须标记或更改数据网格中存在的该数字的颜色.

所以我想知道如何遍历数据网格行和列?以及如何将数据网格单元格内容与用户指定的值进行比较
?

解决方案



您不应该遍历数据网格.您需要做的是创建一个包含数据的结构,其中包括所需的文本颜色,例如:

class GridData : INotifyPropertyChanged
{
   public event PropertyChangedEventHandler PropertyChanged;

   private int _number;
   private SolidColorBrush _textColor;

   public int Number
   {
      get { return _number; }
      set
      {
         number = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("Number"));
         }
      }

   public SolidColorBrush TextColor
   {
      get { return _textColor; }
      set
      {
         _textColor = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("TextColor"));
      }
   }
}



现在,在您的XAML中,将Number属性绑定到在网格列模板中使用的文本框的文本"属性,并将TextColor属性绑定到同一文本框的"Foreground"属性.
每当将TextColor属性从数据类更改为另一种颜色时,PropertyChanged事件都会将更改通知给网格并显示所需的颜色.因此,无需遍历网格本身,只需操作基础数据即可.

希望这对您有帮助...

佩里


您也可以尝试使用转换器 [ ^ ]-尽管可能不会是最快的方法,它是一种更改单元格背景的干净方法.


hi I have one datagird contains 1 to 99 numbers in silverlight 3 .net framework 4.0
i have to find a cell data according to passing parameter and have to mark or change the color of that number that number which present in data grid.

so i want to know How to traverse a datagrid row and coloumn? and How to compare datagrid cell content with user specified value
?

解决方案

Hi,

You should not want to traverse the datagrid. What you need to do is create a structure containing your data, inclusive of the textcolor you need like:

class GridData : INotifyPropertyChanged
{
   public event PropertyChangedEventHandler PropertyChanged;

   private int _number;
   private SolidColorBrush _textColor;

   public int Number
   {
      get { return _number; }
      set
      {
         number = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("Number"));
         }
      }

   public SolidColorBrush TextColor
   {
      get { return _textColor; }
      set
      {
         _textColor = value;
         if (PropertyChanged != null)
         {
            PropertyChanged(this, new PropertyChangedEventArgs("TextColor"));
      }
   }
}



Now, in your XAML, bind the Number property to the "Text" property of the textbox used in your grid columntemplate, and bind the TextColor property to the "Foreground" property of the same textbox.

Whenever you change the TextColor property from your dataclass to another color, the PropertyChanged event will inform the grid of the change and display the desired color. so, no need to traverse the grid itself, just manipulate the underlying data.

Hope this helps in any way...

Regards, Perry


You can also try using a converter [^]- though it may not be the fastest approach, it is a clean approach to change the cell background.


这篇关于Silverlight 3中的datagrid contol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆