Greetings!
I have a xamGrid for an Engineering application where the columns are determined at runtime.
The column definitions (including group columns and fixed columns) are retrieved from an Oracle data source using Entity framework, and served to the silverlight client through RIA services. Due to the flexible nature of the data, all of the columns are added as type TextColumn. I can add the columns and groups without any trouble. In my code to load the columns, I have specified a "ContainingConditionalFormatRule" to apply a style to cells with a certain value as follows:
ContainingConditionalFormatRule notApplicableRule = new ContainingConditionalFormatRule();
notApplicableRule.CellValueVisibility = System.Windows.Visibility.Collapsed;
notApplicableRule.StyleScope = StyleScope.Cell;
notApplicableRule.ShouldRefreshOnDataChange = true;
notApplicableRule.StyleToApply = App.Current.Resources["NotApplicableStyle"] as Style;
notApplicableRule.Value = "#!#";
The style resource is defined as:
<!-- Not applicable cell style -->
<Style x:Key="NotApplicableStyle" TargetType="ig:ConditionalFormattingCellControl">
<Setter Property="Foreground" Value="#FF4C4545" />
<Setter Property="Background" Value="#FF4C4545"/>
<Setter Property="AltBackground" Value="#FF4C4545"/>
</Style>
Each time a column definition is added to the grid, it includes a the following to set add the conditional formatting rule:
col.ConditionalFormatCollection.Add(notApplicableRule);
Each of the data columns has a key that matches a property definition similar to:
[DataMember()]
[Required()]
[StringLength(2000)]
public string Entered1{
get{ return this._entered1;}
set{
if ((this._entered1 != value)){
this.OnEntered1Changing(value);
this.RaiseDataMemberChanging("Entered1");
this.ValidateProperty("Entered1", value);
this._entered1 = value;
this.RaiseDataMemberChanged("Entered1");
this.OnEntered1Changed();
}
Later on, the user will execute a server-side filter to populate the columns. The data is returned as a List<UsrBrowserRowdataSession>, where UsrBrowserRowdataSession is an Entity class returned by my DomainService. I use this list to be the ItemSource of my grid.
When I view the resulting grid, the style does not get applied to each of the columns that contain the value "#!#". However, if I implement the CellControlAttached event handler instead, I am able to inspect the e.Cell.Value.ToString() == "#!#" to apply the same style to the cell. I would rather have the conditional formatting engine do the work, since it does more for me. Does anyone have any thoughts why my Conditional Formatting rule doesn't work, but formatting using the CellControlAttached does?
Hi,
You need to specify what type of rule, you're currently using the base class which won't do anything:
grid.ConditionalFormattingSettings.AllowConditionalFormatting = true;
TextColumn col = new TextColumn() { Key = "ChapterNumber" };
EqualToConditionalFormatRule notApplicableRule = new EqualToConditionalFormatRule();
notApplicableRule.StyleToApply = this.Resources["NotApplicableStyle"] as Style;
notApplicableRule.Value = 1998;
grid.Columns.Add(col);
Hope this helps,
-SteveZ
Hi again,
I didn't specify it specifically, but I did have AllowConditionalFormatting = true. ContainingConditionalFormatRule is one of the inherited classes used for strings containing a specified substring - it inherits from StringConditionalFormatRule, it isn't a base class as far as I can tell (replacing with the EqualToConditionalFormatRule didn't help me, but I tried it just in case).
I'm using GroupColumns extensively for the grid, and I was wondering if those could have been blocking my conditional formatting in some way. When I'm setting up the columns, there are several (at least one, but up to 4) group columns above the text column headers. I add the text columns (which is where the conditional formatting rule is added) to the group header hierarchy. The last step after the groupings are determined and the text columns are added to the group columns is to call grid.Columns.Add( ) for each of the group columns. This didn't appear to be the issue, though, because I tried skipping all of the group columns and added just the text columns, with the same result.
Still looking for something on this one..