如何将背景颜色绑定到另一个 IsSelected 背景
我想将 MyDataGrid 的选定背景颜色绑定到另一个 IsSelected 背景颜色,以便它们共享相同的颜色。我想可以像下面这样完成。我该怎么做呢?
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{Binding ElementName=OtherDataGrid, Path=??Background??" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
I want to bind the selected Background color of MyDataGrid to another IsSelected Background color so they share the same color. I'm thinking it can be done something like below. How can I do it?
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="{Binding ElementName=OtherDataGrid, Path=??Background??" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
共享背景的最佳方法是使用
StaticResource
。The best way to share the background is to use a
StaticResource
.您可以在资源中创建画笔并在两个数据网格中引用它。
喜欢:
You can create a brush in resources and refer that in both the data grids.
Like:
另一种方法是在视图模型中声明一个通知属性并将两种颜色绑定到它。
Another way is to declare a notify property in the view model and bind both colors to it.