I'm trying to change the foreground color of the rows of a xamgrid based on the content of one field. I already have a loop iterating over the grid for a different purpose, so it makes sense to perform the check and color change there if possible. How do I access the row or cell colors, starting with a xamdatagrid object?
Thanks,
John
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Hi Stefan:
Thanks: I saw what you did and tested, it works for me now (had some confusion as to which 'Value' was the 'PropertyName' and not 'Value', heh).
Still, might want to put this into the documentation somewhere as it might be a common issue in the future...?
*Just to leave this up for reference, the solution was to set the DataTrigger's binding to '.....Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.Cells[*PropertyName*].Value}".....'
I have been looking into your sample and I modified it, so now it works as you want. Basically I changed the Binding for the Trigger. Now it is not bound to the DataItem, but to the Cell's Value. I made this change because due to the XamDataGrid virtualization and Record reusing the DataItem was reused and wasn't refreshed. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi:
Thanks for the sample. Everything seems to check out alright in it, and it looks good when it runs.
However, once I modified it, I was able to duplicate the error: I've attached the modified files here.
Basically, the difference was that I began with a viewmodel in the window's resources that was assigned to the datacontext in the xaml, this viewmodel contained the observable list that was originally declared code-behind-side. In the code-behind i referenced the empty list and populated from there.
When you click the button it will keep jumbling the highlighting.
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.