[英]WPF create style binding from code behind
我想在代码隐藏中创建此样式,但是我不知道如何设置对datagrid row属性的绑定。
<UserControl.Resources>
<Style x:Key="MyStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="{Binding SelectedColour[0]}" />
</Style>
</UserControl.Resources>
我该怎么做? 谢谢你安德里亚
只需使用相同的路径创建一个Binding
对象:
Style myStyle = new Style(typeof(DataGridCell));
myStyle.Setters.Add(new Setter(DataGridCell.BackgroundProperty, new Binding("SelectedColour[0]")));
this.Resources.Add("MyStyle", myStyle);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.