是否可以在代码隐藏(C#)中执行以下操作?我想在代码隐藏中绑定BorderBrush
(border元素是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>
谢谢!
答案 0 :(得分:-1)
我没有在边框对象上使用SetBinding
调用绑定,而是直接设置属性:
border.SetValue(Border.BorderBrushProperty, MyDataGrid.HorizontalGridLinesBrush);