WPF如何在代码中创建样式绑定

3
我想在代码后端中创建这个样式,但我不知道如何将绑定设置为数据表行属性。
 <UserControl.Resources>
    <Style x:Key="MyStyle" TargetType="{x:Type DataGridCell}">
        <Setter Property="Background" Value="{Binding SelectedColour[0]}" />
    </Style>
</UserControl.Resources>

我应该怎么做呢? 谢谢 安德烈娅

1个回答

4

只需使用相同路径创建一个Binding对象:

Style myStyle = new Style(typeof(DataGridCell));
myStyle.Setters.Add(new Setter(DataGridCell.BackgroundProperty, new Binding("SelectedColour[0]")));
this.Resources.Add("MyStyle", myStyle);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接