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
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 as of version number 4 doesn't support bindings in a Setter Value. There is a workaround implemented as an attached property:
SetterValueBindingHelper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With