silverlight datagrid - binding each row's style

六眼飞鱼酱① 提交于 2020-01-02 02:08:12

问题


i've got a silverlight (v2) datagrid where some items are section headers and as such must appear with a different background colour.

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>

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()}

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.

(the xaml is based on a wpf implementation of this which works fine)

any input would be much appreciated


回答1:


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>



回答2:


Silverlight as of version number 4 doesn't support bindings in a Setter Value. There is a workaround implemented as an attached property:

SetterValueBindingHelper



来源:https://stackoverflow.com/questions/1176390/silverlight-datagrid-binding-each-rows-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!