我使用这些代码将数据预览显示为工具提示:
private void dataGrid1_RowLoaded(object sender, RowLoadedEventArgs e)
{
var row = e.Row as GridViewRow;
if (row != null)
{
var textBlock = new TextBlock();
textBlock.Text = "...";
textBlock.DataContext = row;
var toolTip = new ToolTip()
{
Content = textBlock,
};
toolTip.Opened += dataGrid1_ToolTipOpening;
ToolTipService.SetToolTip(row, toolTip);
}
}
private void dataGrid1_ToolTipOpening(object sender, RoutedEventArgs e)
{
GridViewRow row = null;
var tooltip = e.OriginalSource as ToolTip;
if (tooltip.Content is UCPreview)
{
return;
}
else if (tooltip.Content is TextBlock)
{
var content = tooltip.Content as TextBlock;
row = content.DataContext as GridViewRow;
}
var gridViewRow = row.Item as DataRowView;
if (gridViewRow != null)
{
//initial UCPreview
}
}
}
现在,我想只有当鼠标在行的标题上时才显示工具提示。遗憾的是,GridViewRow没有Header属性。我该如何解决我的问题?
答案 0 :(得分:0)
如果我没有误解你的问题,试试这个你可以通过在DataGridColumnHeader样式中设置工具提示来做到这一点
<Window.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="dghStyle">
<Setter Property="ToolTip" Value="Red"/>
</Style>
</Window.Resources>
<Grid>
<DataGrid ColumnHeaderStyle="{StaticResource dghStyle}">
<DataGrid.Columns>
<DataGridCheckBoxColumn/>
</DataGrid.Columns>
</DataGrid>
</Grid>
我希望这会有所帮助。这只是解决方法,您可以根据您的要求设置ToolTop。