Silverlight中代码背后的行样式 [英] Row Style in Code Behind in Silverlight
问题描述
我应该在Silverlight中在代码后面设置行样式.实际上,我找不到太多的示例.我有一个颜色转换器,我应该根据一个值设置行的前景和背景.我在链接中检查了示例:
http://blogs.infragistics.com/forums/t/47428.aspx?PageIndex=1
我无法解析CellControl是什么.
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.
<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..
推荐答案
您可以编写如下内容:
You can write something like this:
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;
}
将DataTemplate替换为Style.
希望对您有所帮助.
Replace the DataTemplate with Style.
Hope it helps.
这篇关于Silverlight中代码背后的行样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!