Is it possible to do the following in code-behind (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)
<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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.