wpf - 定义 DataGridTextColumn 工具提示的样式
问题描述
我正在尝试更改 DataGridTextColumn 工具提示的样式,但是下面的 xaml 代码不起作用。当我运行应用程序时,会显示自定义工具提示并在其中写入 System.Windows.Style。该按钮也未显示。我哪里错了?
<DataGrid.Columns>
<DataGridTextColumn Width="*" Binding="{Binding W_NAME}" Header="Name">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<Style TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="HasDropShadow" Value="True"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Content" Value="mytext"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Border Name="RootElement" CornerRadius="2,2,0,0">
<Border.Background>
<SolidColorBrush x:Name="BorderBrush" Color="Black"/>
</Border.Background>
<Grid Margin="4" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
TextElement.FontFamily="{DynamicResource Glaho}"
Content="{TemplateBinding Content}"
Margin="4,5,4,4">
</ContentPresenter>
<Button Content="This is button" HorizontalAlignment="Right" Command="{Binding somecommand}"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
解决方案
您非常接近,问题是您已将其设置Style
为 ToolTip 本身:
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<Style TargetType="ToolTip"> <-------------- badness!
您需要做的是将 ToolTip 控件设置为 ToolTip,然后在其上设置 Style:
<Style TargetType="DataGridCell">
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip>
<ToolTip.Style>
<Style TargetType="ToolTip">
推荐阅读
- web-scraping - 使用 Scrapy 时的不同网页结果
- html - 无法在引导程序 4 中更改导航链接颜色
- javascript - Javascript删除字符串每行的第一个字符
- windows - Windows上的GCC编译到库?
- excel - 在循环中输入不匹配错误,在列中递增地添加数字
- java - 无法从具有 setView 的 AlertDialog 中的 EditText 获取文本
- api - 如何在 Flutter 中使用 CoinMarketCap API
- react-native - 不变违规:本机模块不能在开玩笑反应本机中为空
- intellij-idea - 如何在intellij中显示原始文件结构?
- java - 是否有可能在 Selenium 中刷新某个帧