我正在使用 Microsoft CodePlex 项目中的 WPF 数据网格。我有一个自定义控件,我想将其数据绑定到数据网格行中的字段。我一生都无法弄清楚如何在数据网格行上指定工具提示。
我最接近的是使用 RowStyle 和 Setter 来设置工具提示,但这似乎只适用于文本。当我尝试将 ControlTempalte 作为 ToolTip 的值放入时,它显示在 ControlTemplate 类型上调用 ToString 的结果。
我想我需要设置工具提示的“模板”属性,但我似乎不知道该怎么做......
<dg:DataGrid Name="dgResults" AutoGenerateColumns="True">
<dg:DataGrid.RowStyle >
<Style TargetType="{x:Type dg:DataGridRow}">
<Setter Property="ToolTip" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolTip}">
<StackPanel>
<TextBlock>txt1</TextBlock><TextBlock>txt2</TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</dg:DataGrid.RowStyle>
</dg:DataGrid>
搞清楚了...花了我大约6个小时...
由于某种原因,我无法直接使用 Value.Setter 设置该值。如果我将工具提示的内容定义为静态资源,然后将其设置在 DataGrid.RowStyle 的 Style 属性中,它就可以工作。
因此,数据网格行样式如下所示:
<Style TargetType="{x:Type dg:DataGridRow}">
<Setter Property="ToolTip" Value="{StaticResource resKWIC}">
</Setter>
</Style>
</dg:DataGrid.RowStyle>
并且资源是
<Window.Resources>
<StackPanel x:Key="resKWIC">
<TextBlock>f1</TextBlock>
<TextBlock>f2></TextBlock>
</StackPanel>
</Window.Resources>
Thanks!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)