[英]How to stop tooltips over writing WPF Cell Style
I am currently working on a an App with a colleague that displays quarterly account figures in a data grid.我目前正在与一位同事一起开发一个应用程序,该应用程序在数据网格中显示季度账户数据。 There are some checks that are done on certain columns to see if there are over/under certain thresholds.
对某些列进行了一些检查,以查看是否超过/低于某些阈值。
My colleague built the horizontal Data Grid view/layout (columns are rotated and displays cells left to right)and my task is to format the text and add tool tips to the cells where checks were performed and failed.我的同事构建了水平数据网格视图/布局(列旋转并从左到右显示单元格),我的任务是格式化文本并将工具提示添加到执行检查和失败的单元格。 Thus highlighting on the cell there is issue with the value.
因此在单元格上突出显示值存在问题。
The default cells style is:默认的单元格样式是:
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Focusable" Value="False" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="LayoutTransform">
<Setter.Value>
<TransformGroup>
<RotateTransform Angle="-90"/>
<ScaleTransform ScaleX="1" ScaleY="-1" />
</TransformGroup>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{DynamicResource AppGlobalBackground}">
<ContentPresenter VerticalAlignment="Center"
HorizontalAlignment="Left"/>
<TextBlock>
<ContentPresenter Margin="0,2,10,2"/>
</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource AppGlobalBackground}" />
<Setter Property="Foreground" Value="{DynamicResource AppGlobalForeground}" />
<Setter Property="BorderBrush" Value="{DynamicResource AppGlobalBackground}" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="IsSelected" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
The Data Grid behaves as expected without the tooltip在没有工具提示的情况下,数据网格的行为符合预期
<DataGridTextColumn Binding="{Binding Tax}" >
<DataGridTextColumn.HeaderTemplate >
<DataTemplate>
<TextBlock Text="{Binding DataContext.ViewLabels.Tax, RelativeSource=
RelativeSource AncestorType=DataGrid}}" />
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
However, once a tool tip is added it overrides the Cell style and rotates the data in the cell但是,一旦添加了工具提示,它就会覆盖单元格样式并旋转单元格中的数据
<DataGridTextColumn Binding="{Binding Tax}" >
<DataGridTextColumn.HeaderTemplate >
<DataTemplate>
<TextBlock Text="{Binding DataContext.ViewLabels.Tax, RelativeSource={RelativeSource AncestorType=DataGrid}}" />
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell" >
<Setter Property="ToolTip" >
<Setter.Value>
<ToolTip Visibility="{Binding Path=TaxTT, Converter={StaticResource StringToVisibleTT}}" >
<TextBlock Text="{Binding TaxTT}" />
</ToolTip>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{Binding Path=TaxTT, Converter={StaticResource FormattingConverterTT}}"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
note The visibility converter checks if the tool tip (TaxTT) is an empty string or not & the format converter turns the text red (if the tool tip has text).注意可见性转换器检查工具提示 (TaxTT) 是否为空字符串,格式转换器将文本变为红色(如果工具提示有文本)。
I have read quite a few stack overflow articles about visual trees, but haven't been able to find one that stops it from overriding the normal cells.我已经阅读了很多关于可视化树的堆栈溢出文章,但还没有找到一篇可以阻止它覆盖正常单元格的文章。 Is it at all possible?
有可能吗?
custom CellStyle should inherit base style for DataGridCell:自定义 CellStyle 应继承 DataGridCell 的基本样式:
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<Setter Property="ToolTip" >
<Setter.Value>
<ToolTip Visibility="{Binding Path=TaxTT, Converter={StaticResource StringToVisibleTT}}" >
<TextBlock Text="{Binding TaxTT}" />
</ToolTip>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="{Binding Path=TaxTT, Converter={StaticResource FormattingConverterTT}}"/>
</Style>
</DataGridTextColumn.CellStyle>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.