I would like to create this styel in codebehind, but I don't know how to set the binding to the datagrid row property.
<UserControl.Resources>
<Style x:Key="MyStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{Binding SelectedColour[0]}" />
</Style>
</UserControl.Resources>
How can I do it? Thank you Andrea
Just create a Binding object with the same path:
Style myStyle = new Style(typeof(DataGridCell));
myStyle.Setters.Add(new Setter(DataGridCell.BackgroundProperty, new Binding("SelectedColour[0]")));
this.Resources.Add("MyStyle", myStyle);
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