到目前为止,我没有得到任何答案,如果有人知道如何解决这个问题.. 请告诉我。谢谢
我有以下情况:
我在 UI 的中心绘制了两个带有红色 X 的椭圆。
我正在使用中心椭圆将它们拖到我想要的屏幕上。它工作得非常好,如果我不点击红色的 X,我可以看到椭圆在每次鼠标移动时都被重新绘制。
我遇到的问题是这样的:
每次单击红色 X 时,我都不再看到椭圆重新绘制。但是一旦 LeftButton 向上,Ellipses 就会转到正确的位置。
有没有人知道可能会发生什么?
提前致谢。
[编辑1]
private void canvasArea_MouseMove(object sender, MouseEventArgs e)
{
if ((e.LeftButton == MouseButtonState.Pressed) && flag_centerEllipse_MouseLeftButtonDown)
{
flag_UpdateEllipseCenter = true;
UpdateEllipseCenter();
DrawingEllipse();
}
else
flag_UpdateEllipseCenter = false;
}
我确信这两个条件都满足了。
[编辑2]
private void centerEllipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
flag_centerEllipse_MouseLeftButtonDown = true;
}
确保该变量为真。
[编辑3]
为了帮助澄清我的问题:http ://s14.postimg.org/6sajsb5tp/ellipse.png
[编辑4]
xml代码:
<Canvas Background="Transparent" Name="canvasArea" MouseLeftButtonDown="canvasArea_MouseLeftButtonDown" MouseMove="canvasArea_MouseMove" MouseLeftButtonUp="canvasArea_MouseLeftButtonUp">
<TextBlock Canvas.Left="612" Canvas.Top="577" Height="23" Name="tBCreationTime" Text="TextBlock" />
<TextBlock Canvas.Left="447" Canvas.Top="577" Height="23" Name="tBCoordinates" Text="TextBlock" Width="160" />
<Ellipse Name="externalEllipse" Height="0" Width="0" MouseLeftButtonDown="externalEllipse_MouseLeftButtonDown" MouseLeftButtonUp="externalEllipse_MouseLeftButtonUp"/>
<Ellipse Name="centerEllipse" Height="0" Width="0" MouseLeftButtonDown="centerEllipse_MouseLeftButtonDown" MouseLeftButtonUp="centerEllipse_MouseLeftButtonUp"/>
<Line Name="targetHorizontal"></Line>
<Line Name="targetVertical"></Line>
</Canvas>
更新椭圆中心:
private void UpdateEllipseCenter()
{
Point newEllipseCenter = Mouse.GetPosition(canvasArea);
ellipseCenter = newEllipseCenter;
}
绘制椭圆和直线:
private void DrawingEllipse()
{
bool addRmvObjcts = true;
if (mousePositionDown.X != mousePositionUp.X && mousePositionDown.Y != mousePositionUp.Y)
{
addRmvObjcts = AddRemoveCanvasObjects(addRmvObjcts);
if (flag_UpdateEllipseSize || flag_UpdateEllipseCenter)
{
externalEllipse.Height = externalEllipse.Width = drawHypotenuse;
}
else
{
double diffX = mousePositionUp.X - mousePositionDown.X;
double diffY = mousePositionUp.Y - mousePositionDown.Y;
drawHypotenuse = Math.Sqrt(Math.Pow((diffX), 2) + Math.Pow((diffY), 2));
externalEllipse.Height = externalEllipse.Width = drawHypotenuse;
ellipseCenter.X = ((mousePositionDown.X + ((mousePositionUp.X - mousePositionDown.X) / 2)));
ellipseCenter.Y = ((mousePositionDown.Y + ((mousePositionUp.Y - mousePositionDown.Y) / 2)));
}
AddRemoveCanvasObjects(addRmvObjcts);
SettingObjectsPosition();
}
}