在一个ChildWindow里使用TabControl分两个TabItem,
每个TabItem都有一个DataGrid。
给两个DataGrid里的行设置了ToolTipService
代码如下
private void dgMaintain_LoadingRow(object sender, DataGridRowEventArgs e)
{
int index = e.Row.GetIndex();
var maintain = e.Row.DataContext as Maintain;
if (maintain != null)
{
ToolTipService.SetToolTip(e.Row, tipStrings.GetMaintainListTips(maintain));
}
}
private void dgLedger_LoadingRow(object sender, DataGridRowEventArgs e)
{
int index = e.Row.GetIndex();
var ledger = e.Row.DataContext as Ledger;
if (ledger != null)
{
ToolTipService.SetToolTip(e.Row, tipStrings.GetLedgerListTips(ledger));
}
}
运行后,鼠标滚动DataGrid的行,
ToolTipService.SetToolTip(); 会报错
用户代码未处理 System.Exception
Message=对 COM 组件的调用返回了错误 HRESULT E_FAIL。
StackTrace:
位于 子窗体.dgLedger_LoadingRow(Object sender, DataGridRowEventArgs e)
位于 System.Windows.Controls.DataGrid.OnLoadingRow(DataGridRowEventArgs e)
位于 System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot, Object dataContext)
位于 System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex, Int32 slot)
位于 System.Windows.Controls.DataGrid.InsertDisplayedElement(Int32 slot, Boolean updateSlotInformation)
位于 System.Windows.Controls.DataGrid.GetExactSlotElementHeight(Int32 slot)
位于 System.Windows.Controls.DataGrid.UpdateDisplayedRows(Int32 newFirstDisplayedSlot, Double displayHeight)
位于 System.Windows.Controls.DataGrid.ScrollSlotsByHeight(Double height)
位于 System.Windows.Controls.DataGrid.OnRowsMeasure()
位于 System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size availableSize)
位于 System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight) InnerException: