问题描述
我已经有了,一些项节标题,因此必须用不同的背景颜色出现一个Silverlight(V2)数据网格。
i've got a silverlight (v2) datagrid where some items are section headers and as such must appear with a different background colour.
我试图用下面的XAML做到这一点:
i'm trying to do this with the following xaml:
<dg:DataGrid.RowStyle>
<Style TargetType="dg:DataGridRow">
<Setter Property="Background" Value="{Binding Path=Background, Mode=OneTime}" />
</Style>
</dg:DataGrid.RowStyle>
我希望它的DataGrid行视图模型的背景属性绑定到每个行的背景属性,而不是我得到一个可爱的未知的xaml分析错误:
i expect it to bind the Background property of the datagrid row viewmodel to each row's Background property, instead i get a lovely unknown xaml parsing error:
{System.Windows.Markup.XamlParseException: AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR [Line: 16 Position: 57]
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Etana.Survey.Silverlight.UserInterface.Views.MaximumProbableLossPage.InitializeComponent()
at Etana.Survey.Silverlight.UserInterface.Views.MaximumProbableLossPage..ctor()}
如果我尝试显式指定红色和不要试图并绑定风格,那么它的作品,所以我不知道的Silverlight可以让我一个风格绑定一样,或者,如果有一些其他的把戏吧。
if i try to explicitly specify "Red" and not try and bind the style, then it works, so I wonder if silverlight would allow me to bind a style like that or if there's some other trick to it.
(将XAML是基于WPF执行本该正常工作)
(the xaml is based on a wpf implementation of this which works fine)
任何投入将是非常感谢
推荐答案
更改绑定TemplateBinding。例如:
Change your binding to TemplateBinding. eg
<dg:DataGrid.RowStyle>
<Style TargetType="dg:DataGridRow">
<Setter Property="Background" Value="{TemplateBinding Background, Mode=OneTime}" />
</Style>
</dg:DataGrid.RowStyle>
这篇关于Silverlight的DataGrid的 - 绑定每个行的风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!