Click here to Skip to main content
15,909,039 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I should set row style in code behind in silverlight.Actually I couldn't find so much sample about this. I have a color converter, I should set foreground and background of the rows according to a value. I check the sample in the link:

http://blogs.infragistics.com/forums/t/47428.aspx?PageIndex=1

I couldn't resolve the CellControl what it is.

XML
<sdk:DataGrid.RowStyle>
 <Style TargetType="sdk:DataGridRow">
   <Style.Setters>
      <Setter Property="Background" Value="{Binding Path=myProperty ,Converter={StaticResource myConverter}}"/>
         <Setter Property="Foreground" Value="{Binding Path=myProperty, Converter={StaticResource myForegroundConverter}}" />
        <Setter Property="FontFamily" Value="Verdana"></Setter>
       </Style.Setters>
 </Style>



Or how can I set this situation in code behind?

Thanks in advance for the replies..
Posted
Updated 12-Mar-12 21:19pm
v6

1 solution

You can write something like this:
C#
private DataTemplate SetButtonContent()
        {
            StringBuilder sb = new StringBuilder();
            
            sb.Append("<datatemplate hold=" />            sb.Append(" xmlns="http://schemas.microsoft.com/winfx/");<br mode="hold" />            sb.Append("2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">");
            sb.Append("<stackpanel orientation="Horizontal"> ");
            sb.Append("<image source="Images/Click.png" width="32" height="32" hold=" />            sb.Append(" stretch="Uniform" verticalalignment="Center" horizontalalignment="Left" /> ");
            sb.Append("<textblock text="Click Me!" horizontalalignment="Left" verticalalignment="Center" />");
            sb.Append("</stackpanel> </datatemplate>");
            
            DataTemplate dt = XamlReader.Load(sb.ToString()) as DataTemplate;
            return dt;
        }


Replace the DataTemplate with Style.

Hope it helps.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900