【发布时间】:2014-09-14 18:54:00
【问题描述】:
我的 DataGridCell 样式中的 ToolTip 有问题。当我尝试在工具提示中显示单元格的内容时,此内容会消失。我必须在每个单元格上显示此工具提示,并且动态生成列,因此我无法绑定到任何属性名称。这是我的sn-p:
<Style x:Key="dgCellStyle" TargetType="{x:Type Controls:DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<Grid Background="{TemplateBinding Background}">
<ToolTipService.ToolTip>
<ContentControl Content="{TemplateBinding Content}" />
</ToolTipService.ToolTip>
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Margin="0,2"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey ResourceId=FocusBorderBrushKey, TypeInTargetAssembly={x:Type Controls:DataGrid}}}"/>
</Trigger>
</Style.Triggers>
</Style>
有人知道吗? 谢谢
【问题讨论】:
-
您最好检查 [this][1] 问题。 [1]:stackoverflow.com/questions/7173430/…
-
感谢您的回复,但您发布的链接是关于 winforms 的,我需要 wpf 框架的解决方案,而不是通过代码,而是通过 xaml 方式。
标签: c# wpf styles wpfdatagrid