以编程方式扩展 DataGrid ColumnHeaderStyle
我通过 ResourceDictionary 定义 DataGridColumnHeader 的样式,其中有一个 Setter:
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
等等(并不是很重要。
现在我想通过 ColumnHeader 的工具提示来扩展样式。我必须在代码中设置此工具提示,因为它与在某些情况下,
我可以这样做:
var style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader));
style.Setters.Add(new Setter(ToolTipService.ToolTipProperty,"my tooltop"));
dgcol1.HeaderStyle = style;
但显然资源字典中的所有其他样式设置器都会被覆盖。 如何通过代码将工具提示添加到 ColumnHeader? 有人知道吗?谢谢你!
I'm defining the style of DataGridColumnHeader by ResourceDictionary with a Setter there:
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
and so on (not really important.
Now I want to extend the style by a tooltip for the ColumnHeader. I have to set this tooltip in code because it is different for some situations.
I could do it that way:
var style = new Style(typeof(System.Windows.Controls.Primitives.DataGridColumnHeader));
style.Setters.Add(new Setter(ToolTipService.ToolTipProperty,"my tooltop"));
dgcol1.HeaderStyle = style;
But obviously all other style setters from the recource dictionary are overwritten then.
How can I add my tooltip to the ColumnHeader by code?
Does anyone have any idea? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以尝试这个
后面的代码
希望这会有所帮助......
you can try this one
code behind
hope this helps...