I have a XamDataGrid that shows a lot of data. I would like to write C# that will modify the background of a specific cell or row in the grid. I do not want to put any of the background logic in the presentation layer (xaml file), so triggers would not be a desired option.
Could someone please post some C# sample code?
Thank you in advance.
-Ben
Ben,
The best approach is to use Triggers because the visual elements of the grid are recycled and as you scroll they are reused. As such if you do set the Background of one of these elements in code, when you scroll, the background will be on a record that it may not apply to. When the visual elements are reused by another record, a Trigger would be reevaulated.
The following knowledge base article has one possible approach where the logic is in c# or VB code in a converter http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10107. Would this approach work for you?
Hi Alan,
Thank you for the suggestion. Also, thanks for the link to the article.
Is there some sample code on how to make a trigger than will cause a background color of a cell to appear for only a few seconds? For example, I'd like a data change to cause the cell to highlight for 5 seconds, and then revert to the normal background color. I did some searching on the web, and found sample code for triggers, but I don't believe I've come across a trigger than will temporarily show the color change.
Any information is greatly appreciated.
Brian,
In the StoryBoard with Key cellValueChangedSB, simply change the FillBehavior of the ColorAnimation to HoldEnd rather than Stop and the color will stay in the cell after the change.
Let me know if you have any questions with this matter.
Alan,
I did try that and while it seems good, when you mouse over the cell, the color disappears!
In one of your earlier posts in this thread, you said you were using the Storyboard to handle the ability to change the color to Red and then back to its original color after the Storyboard finishes. It seems like this is happening here. While the color "holds" it is not permanent.
I am looking for a solution where based on a criteria/logic, the background color may be set to a different color. I need this color to stay as long as the criteria/logic holds true. Do you have an example that does this? Or how can I modify this example to do so?
Thanks,
-Brian
Have you looked at the sample on the Knowledge Base article that I referenced earlier in this thread? I believe that approach may be better for you.
I am trying to accomplish the same. The issue I keep running into is that these converters greatly extend loading time and do not necessarily rebind when an observed value in the grid changes. Too many converters slows your app down - that's bad.
My goal is to hightlight a row based on a stored property value which is to be matched to a cell in the list of grid records.
If that property value is set after the grid is loaded, the converter will not find the value. Subsequenty if the property changes, the converter won't be notified.
In other words, if I could fire the converter at the appropriate time to search for the desired row in the grid and highlight it, that would work. I still don't like converters drilling through all my data at load time.
If there was a solution which could be done via managed code and not xaml, I could control when the row is highlighted. That does not appear to be the case.
Glenn
Glenn,
Depending on where you are storing the value that you are looking to use for calculations, you may be able to use a MultiValueConverter to pass in multiple values. Another possible alternative would be to use the Tag property of the Record and bind the Background to this and then you could set the Tag of the Record in code when you need to.
Let me know if either of those would work for you.