Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: XAML WPF C#4.0 DataGrid
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 place.it require some overrid how i can aproach this
thanks in advance
Posted 26-Jan-12 10:38am
Comments
SAKryukov at 26-Jan-12 15:46pm
   
Why do you think this is override? Is the property bound, and how?
--SA
SAKryukov at 26-Jan-12 15:47pm
   
Please don't re-post.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What's the problem? What's wrong with MyDataGrid.Rowbackground = someBruh;?
 
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.rowbackground%28v=vs.95%29.aspx[^].
 
See also this CodeProject thread: http://beta.codeproject.com/Messages/4078126/Datagrid-Row-background-binding-issue.aspx[^].
 
[EDIT]
 
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[^].
 
—SA
  Permalink  
v2
Comments
MohammadIqbal at 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 at 26-Jan-12 16:26pm
   
Well, how do you know this code was called? Put a break point on it.
--SA
Espen Harlinn at 26-Jan-12 16:10pm
   
5'ed! Wayne Gaylard reply to the thread you referenced should work nicely:
http://beta.codeproject.com/Messages/4078525/Re-Datagrid-Row-background-binding-issue.aspx
SAKryukov at 26-Jan-12 16:25pm
   
Thank you, Espen.
--SA
Rate this: bad
good
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
  Permalink  
v2
Comments
SAKryukov at 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).
--SA
SAKryukov at 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. :-)
--SA
Espen Harlinn at 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 at 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...
--SA
Espen Harlinn at 26-Jan-12 17:11pm
   
Pity, I'd like a link to that article ...
SAKryukov at 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,
--SA
Espen Harlinn at 26-Jan-12 17:15pm
   
Thanks :)
That should work well enough, and it will provide excellent flexibility.
SAKryukov at 26-Jan-12 20:39pm
   
That was my impression, too.
Thank you.
--SA

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 26 Jan 2012
Copyright © CodeProject, 1999-2014
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