Click here to Skip to main content
13,148,503 members (52,547 online)
Rate this:
Please Sign up or sign in to vote.
I have DataGrid whose RowBackGround and alternating RowBackGround set to black at the design time itself.
an as the part of event triggered theme change I want to include AlternatingRowBackGround and RowBackGround to be set during run time (to some other color) but it is not taking require some overrid how i can aproach this
thanks in advance
Posted 26-Jan-12 9:38am
SAKryukov 26-Jan-12 15:46pm
Why do you think this is override? Is the property bound, and how?
SAKryukov 26-Jan-12 15:47pm
Please don't re-post.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What's the problem? What's wrong with MyDataGrid.Rowbackground = someBruh;?

Please see:[^].

See also this CodeProject thread:[^].


Please see the answer by Espen and our comments in his thread. Crediting Espen's note on the styles, I mentioned the article which you could find useful:
WPF Themes and Skins Engine[^].

MohammadIqbal 26-Jan-12 15:48pm
I have set these properties at design time to certain colors. and during run time I set RowBackground to some brush in the AutoGeneratecolumn event handler. but it do not have any effect.
SAKryukov 26-Jan-12 16:26pm
Well, how do you know this code was called? Put a break point on it.
Espen Harlinn 26-Jan-12 16:10pm
5'ed! Wayne Gaylard reply to the thread you referenced should work nicely:
SAKryukov 26-Jan-12 16:25pm
Thank you, Espen.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Have a look at:Styling Microsoft’s WPF datagrid[^]

Rembemer that styles can be inherited[^] too.

Create new styles for your application that inherits from the ones you want to work with your application and apply appropriate setters. This way you will not need to handle any events in your application.

WPF DataGrid Practical Examples[^] provides a good introduction to the WPF DataGrid.

Best regards
Espen Harlinn
SAKryukov 26-Jan-12 16:32pm
This is very appropriate, my 5.

So, maybe OP should review the design instead of just straightforward manipulation with the property (which he failed to achieve so far, please see his comment to my answer).
SAKryukov 26-Jan-12 16:36pm
By the way, as to the last links: if I'm not mistaken, OP asked for a book or a site about this very control, and you appreciated my answer (very general though). Maybe this relatively short and nice article will serve as a book or a Web site for OP... :-)

Another 5... Oops! despite of the beta version of the site, only one 5 is taken into account. :-)
Espen Harlinn 26-Jan-12 16:41pm
Thank you, Sergey!
Personally I think deriving from existing styles would be in line with the design philosophy of WPF :)
SAKryukov 26-Jan-12 17:08pm
Good style system should be cascading. I recently referenced a CodeProject article where the author introduced pretty much universal systems to support WPF skins. As far as I understand, it is nice and mature work; and it is inline with the design philosophy you mentioned.

It would take some time to find it on CodeProject again...
Espen Harlinn 26-Jan-12 17:11pm
Pity, I'd like a link to that article ...
SAKryukov 26-Jan-12 17:14pm
Yes, found it; it was easy. I added the update to my answer and credited your comment. You will find that reference, after [EDIT].

I would appreciate if later on you could tell me your opinion.

Thank you,
Espen Harlinn 26-Jan-12 17:15pm
Thanks :)
That should work well enough, and it will provide excellent flexibility.
SAKryukov 26-Jan-12 20:39pm
That was my impression, too.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 26 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100