我使用这些代码将数据预览显示为工具提示:
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 属性。我该如何解决我的问题?