Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

silverlight datagrid - binding each row's style

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

like image 502
Veli Gebrev Avatar asked Jul 24 '09 08:07

Veli Gebrev


2 Answers

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>
like image 95
Geoff Appleford Avatar answered Nov 15 '22 08:11

Geoff Appleford


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

SetterValueBindingHelper

like image 27
Pablo Montilla Avatar answered Nov 15 '22 08:11

Pablo Montilla