Hello,
I have following problem with XamGrid:I want to use conditional formatting of cells with StyleScope="Row", according to a value of a cell in XamGrid should be changed the foreground colour (red) of the whole row. I set the "conditional" column to values in order to set foreground colour in whole XamGrid to red. Everything was OK, until conditional formatting changed the style of visible rows. When I scrolled to see other rows, I was surprised, because some of them were red, some of them were not. When I scrolled to the beginning to see the first rows, theyhad the same problem! Other thing is, that it behaved indeterminately - for example I had 5 visible rows in XamGrid, but I had 7 rows in the whole grid. So I had to scroll to seethe 6. and 7. row, but sometimes the 6. row had the style not set, sometimes the 7. has the same problem, but the 6. was set.
After these troubles I tried to set foreground colour "directly" in code in this way:
Brush BlackForegroundBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0, 0, 0));Brush RedForegroundBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0xFF, 0, 0));Brush brush;
foreach (Row row in grid.Rows){ VxSJEmisia emisia = row.Data as VxSJEmisia; if (emisia != null) { if (emisia.Valid) { brush = BlackForegroundBrush; } else { brush = RedForegroundBrush; }
foreach (Cell cell in row.Cells) { if (cell != null && cell.Control != null) { cell.Control.Foreground = brush; } } }}
But the XamGrid had the same behavior.Surprisingly in some cases the cell.Control has null value in existing XamGrid !
Please, could somebody help me with this? Thanks a lot.
Hi,
This works fine, however when I change the StyleScope to "Row" it does not work.
I am using SL4 though, could that make a difference?
Thank you for your post. I have been looking into and I created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
Sorry to hijack the thread but I have a similar issue and have altered the sample application to show this issue.
Basically if I apply a grid.cellstyle it overrides the row.cellstyle.
According to this post: http://ko.infragistics.com/community/forums/p/37026/216198.aspx#216198
row.cellstyle is higher priority than grid.cellstyle. Is this intended or broken?
Is there a way to apply a style to the grid, but also have conditional formatting on the row?
I have tried your solution, and it works fine (even without Service Release).
Thanks a lot.
So you are changing values and you want the style to reflect that.
First you need to set the rule to update the conditional formatting rule designation to update on data change
<ig:EqualToConditionalFormatRule StyleScope="Cell" Value="2"
StyleToApply="{StaticResource RedStyle}" ShouldRefreshOnDataChange="true"
></ig:EqualToConditionalFormatRule>
And the data object wasn't robust enough to show how that could be done. It was only intended to check
the setting of StyleScope.
So if you want the grid to respond to data changes then the data object needs to implement
INotifyPropertyChanged.
public class Person : INotifyPropertyChanged { public int ID { get; set; } public string Name { get; set; } public int IDMod4 { get { return this._idMod4; } set { if (this._idMod4 != value) { this._idMod4 = value; this.OnNotifyPropertyChanged("IDMod4"); } } } private int _idMod4; protected virtual void OnNotifyPropertyChanged(string propName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion } If you don't implement this interface then the grid cannot know that changes happened to the underlying data.
public class Person : INotifyPropertyChanged { public int ID { get; set; } public string Name { get; set; } public int IDMod4 { get { return this._idMod4; } set { if (this._idMod4 != value) { this._idMod4 = value; this.OnNotifyPropertyChanged("IDMod4"); } } } private int _idMod4; protected virtual void OnNotifyPropertyChanged(string propName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion }
If you don't implement this interface then the grid cannot know that changes happened to the
underlying data.