简体   繁体   English

在代码隐藏中绑定 BorderBrush

[英]Bind BorderBrush in Code-Behind

Is it possible to do the following in code-behind (C#)?是否可以在代码隐藏 (C#) 中执行以下操作? I want to bind the BorderBrush in code-behind (the border element is a child inside a DataGrid cell and the color of this border must match the color specified for the DataGrid's vertical grid lines color)我想在代码隐藏中绑定BorderBrush (边框元素是DataGrid单元格内的子元素,此边框的颜色必须与为 DataGrid 的垂直网格线颜色指定的颜色相匹配)

<Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=VerticalGridLinesBrush}" BorderThickness="0 0 1 0" Grid.Column="0">
    <TextBlock Name="tbMyBlock" Text="My Text Block" />
</Border>

Thanks!谢谢!

我没有在我的边框对象上使用SetBinding调用进行绑定,而是直接设置属性:

border.SetValue(Border.BorderBrushProperty, MyDataGrid.HorizontalGridLinesBrush);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM