Yes, using DataBining and IValueConverter to do this is the right way. If you need to set the whole row color, you still need to do it for each column because there is no way to set the whole row background color or text color in the current DataGrid.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
In the datatemplate, bind the data to a textbox, From the codebehind, depending on the condition change the background of the textbox, Have the size of the textbox to auto so it fills the whole row and height. Make the enabling false.
Hope this is helpful.
If this post was helpful then please 'Mark as Answer'
Sharker Khaleed Mahmud
Sr. Software Developer
(MCP,MCTS,MCPD[web])
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
silverbyte
Participant
1392 Points
482 Posts
Update datagrid row text color based on bounded data property value
Nov 14, 2008 10:39 PM | LINK
Hello,
I need to update the row text font based on bounded data.
For example, let's say I have a class Person with a property bool HasChildren.
I want to display the row's text in red for each Person which HasChildren is rue.
What's the best way to do this ?
Thanks.
silverbyte
Participant
1392 Points
482 Posts
Re: Update datagrid row text color based on bounded data property value
Nov 14, 2008 10:45 PM | LINK
I think I know how to do this: bind the row Foreground property to HasChildren using a IValueConverte which returns a brush
silverbyte
Participant
1392 Points
482 Posts
Re: Re: Update datagrid row text color based on bounded data property value
Nov 14, 2008 10:59 PM | LINK
What I need in fact is to set the whole row color.
sladapter
All-Star
43609 Points
7910 Posts
Re: Re: Update datagrid row text color based on bounded data property value
Nov 15, 2008 03:03 AM | LINK
Yes, using DataBining and IValueConverter to do this is the right way. If you need to set the whole row color, you still need to do it for each column because there is no way to set the whole row background color or text color in the current DataGrid.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
shamrat231
Star
10748 Points
1283 Posts
Re: Re: Update datagrid row text color based on bounded data property value
Nov 15, 2008 03:24 AM | LINK
In the datatemplate, bind the data to a textbox, From the codebehind, depending on the condition change the background of the textbox, Have the size of the textbox to auto so it fills the whole row and height. Make the enabling false.
Hope this is helpful.
If this post was helpful then please 'Mark as Answer'
Sharker Khaleed Mahmud
Sr. Software Developer
(MCP,MCTS,MCPD[web])
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Follow me on Twitter :: www.silverlightips.net
silverbyte
Participant
1392 Points
482 Posts
Re: Re: Re: Update datagrid row text color based on bounded data property value
Nov 15, 2008 12:13 PM | LINK
Does any of you know about a known problem with binding the Foreground property and using IValueConverter on a DataGridTextColumn ?
On a TextBlock in a DataGridTemplateColumn this works fine:
Foreground="{Binding Item.IsDeleted, Converter={StaticResource ItemDeletedBrushConverter}}"
But setting the exactly the same line on a DataGridTextColumn throws an exception:
Item is a class having a boolean IsDeleted public property and again it works fine on DataGridTemplateColumn.
Obviously setting Foreground to {Red} for example does work for DataGridTextColumn.
Any idea ?