在WPF中,使用鼠标位置移动图像时防止光标闪烁
我有一个图像,当鼠标移动时,我正在更新它在画布上的位置在WPF中,使用鼠标位置移动图像时防止光标闪烁,wpf,image,canvas,cursor,wpf-controls,Wpf,Image,Canvas,Cursor,Wpf Controls,我有一个图像,当鼠标移动时,我正在更新它在画布上的位置 <Popup Name="floatingTip" AllowsTransparency="True" Placement="Relative" PlacementTarget="{Binding ElementName=MainCanvas}"> <Image Source="{Binding Name}" Width="{Binding Wi
<Popup Name="floatingTip" AllowsTransparency="True" Placement="Relative"
PlacementTarget="{Binding ElementName=MainCanvas}">
<Image Source="{Binding Name}"
Width="{Binding Width}"
Height="{Binding Height}"/>
</Popup>
当光标在画布内移动时,我会更新包含图像的弹出窗口的位置:
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (!floatingTip.IsOpen && currentTool == "staticBrush")
{
floatingTip.IsOpen = true;
}
if (currentTool == "staticBrush" && lvDataBinding.SelectedIndex != -1)
{
Point currentPos = e.GetPosition(this);
floatingTip.HorizontalOffset = currentPos.X - (cursorImage.Width / 2.0);
floatingTip.VerticalOffset = currentPos.Y - (cursorImage.Height / 2.0);
cursorImage.Width = 50;
cursorImage.Height = 50;
}
}
当鼠标离开画布时,我将光标设置回Cursors.aror
如果图像不在光标下方,也就是说,如果我稍微偏移图像的位置,一切都会正常工作。但是如果我把图像直接放在光标下面,图像就会随着箭头光标开始闪烁(即使光标是隐藏的)。我猜出来了。我需要将图像上的IshtestVisible设置为false
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (!floatingTip.IsOpen && currentTool == "staticBrush")
{
floatingTip.IsOpen = true;
}
if (currentTool == "staticBrush" && lvDataBinding.SelectedIndex != -1)
{
Point currentPos = e.GetPosition(this);
floatingTip.HorizontalOffset = currentPos.X - (cursorImage.Width / 2.0);
floatingTip.VerticalOffset = currentPos.Y - (cursorImage.Height / 2.0);
cursorImage.Width = 50;
cursorImage.Height = 50;
}
}