Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#更改CustomFieldData事件的背景颜色_C#_Wpf_Devexpress - Fatal编程技术网

C#更改CustomFieldData事件的背景颜色

C#更改CustomFieldData事件的背景颜色,c#,wpf,devexpress,C#,Wpf,Devexpress,我有一个PivotDataGrid,运行良好。还添加了CustomUnboundFieldData,但现在我想根据此字段中的值更改单元格的背景色 要更改颜色,我使用customCellAppearance事件。只有在我操作未绑定字段数据中的值后才会触发此事件 所以我的问题基本上是,如何改变细胞的背景。是否使用未绑定字段数据事件 下面是一段代码 //create unbound field PivotGridField unboundField = pivot.Control.Fields.Add

我有一个PivotDataGrid,运行良好。还添加了CustomUnboundFieldData,但现在我想根据此字段中的值更改单元格的背景色

要更改颜色,我使用customCellAppearance事件。只有在我操作未绑定字段数据中的值后才会触发此事件

所以我的问题基本上是,如何改变细胞的背景。是否使用未绑定字段数据事件

下面是一段代码

//create unbound field
PivotGridField unboundField = pivot.Control.Fields.Add("unboundDataField", FieldArea.FilterArea);
unboundField.UnboundType = FieldUnboundColumnType.String;

//fill unbound field with data
private void Control_CustomUnboundFieldData(object sender, PivotCustomFieldDataEventArgs e)
{         

    String myValue = Convert.ToString(e.GetListSourceColumnValue("sourceColumn"));              
    e.Value = myValue.Substring(6);
    e.Field.SummaryType = FieldSummaryType.Max;            
} 

//code to change appearance of different cells
private void Control_CustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
{    
    if(e.Value != null)
    {
        e.Background = System.Windows.Media.Brushes.Green; 
    }

}      

要根据“原始数据”更改颜色,请使用CreateDrillDownDataSource方法

使用此方法,u可以获得源列,并根据方法得出的值更改单元格的背景颜色

下面是一段代码片段:

    private void Control_CustomCellAppearance(object sender, PivotCustomCellAppearanceEventArgs e)
    {
         PivotDrillDownDataSource ds = e.CreateDrillDownDataSource();
         //get value from the original source according to the row index
         String myValue = Convert.ToString(ds.GetValue(e.RowIndex, "sourceColumn"));

         //backgroundcolor condition
         if(myValue.Containts("something"))
         {
            e.Background = System.Windows.Media.Brushes.Green; 
         }
    }

有关更多信息,请参阅devexpress网站:

,您的哪一行代码负责更改颜色?功能“Control\u CustomCellAppearance”负责更改颜色。我刚才添加了这个函数。