views:

1789

answers:

3

hi,

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

A: 

have you tried changing the type of VM.Background from a string to a SolidColorBrush?

SmartyP
I did, got exactly the same error. Even attempting to bind a bool property (IsReadOnly) results in the error getting thrown. Oh well, I guess my work-around will have to do.
Veli
+1  A: 

Change you binding to to TemplateBinding. eg

<dg:DataGrid.RowStyle>
            <Style TargetType="dg:DataGridRow">
                <Setter Property="Background" Value="{TemplateBinding Background, Mode=OneTime}" />
            </Style>
</dg:DataGrid.RowStyle>
geoff
A: 

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

SetterValueBindingHelper

Pablo Montilla
thanks for that, sure it will come in handy for people looking for a solution in v4, the question was asked explicitly for v2 though :)
Veli
Exactly what I meant...I came to this post while looking for a solution to that problem and this answer didn't help. Will edit the post.
Pablo Montilla