我正在为图表内容实现一个“鼠标悬停值”的读数。目前我是通过使用ReactiveExtensions并订阅我的图表背景网格上的GetMouseMove事件来实现这一点:
private void SetupMouseover( Grid plotArea)
{
var mouseMove = from mo in plotArea.GetMouseMove()
select new
{
CurrentPos = mo.EventArgs.GetPosition( plotArea )
};
mouseMove.Subscribe(
item =>
{
// Update the readout contents
readoutTextBlock.Text = PositionToReadoutValue(item.CurrentPos);
}
);
}
这很好用。我可以移动鼠标并更新文本块。
问题在于图表内容正在动态更新(在屏幕上移动)。如果我将鼠标光标保持静止在某个点上,下面的内容会改变,但(显然)读数不会更新。
我尝试通过在模型数据更新时将光标位置设置为其自身来手动触发鼠标移动:
private void MoveCursor()
{
// move the mouse cursor 0 pixels
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X,
System.Windows.Forms.Cursor.Position.Y);
}
这没有触发回调函数。将位置设置为(X-1,Y-1)会触发回调,但如果我立即将像素点返回到原始位置(后续的X+1,Y+1),则不会触发任何位置设置的mousemove回调。
我还尝试了根据Mouse.GetPosition(m_PlotArea)的模型更改通知手动设置readoutTextBlock,但遇到了线程问题(模型在单独的线程中更新)以及与m_PlotArea的命中测试问题。
有什么建议吗?