到目前为止,我没有回答,如果有人知道如何解决这个问题,请告诉我。感谢
我有以下情况:
我在UI的中心画了两个椭圆,红色的X.
我正在使用椭圆中心将它们拖到我想要的任何地方。它的效果非常好,如果我没有点击红色的X,我可以看到每次鼠标移动都会重新绘制椭圆。
我遇到的问题是:
每当我点击红色X时,我就会停止看到Ellipses重新绘制。但是一旦LeftButton上升,椭圆就会到达正确的位置。
有没有人知道可能会发生什么?
提前致谢。
[EDIT1]
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;
}
我确信这两个条件都得到了满足。
[EDIT2]
private void centerEllipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
flag_centerEllipse_MouseLeftButtonDown = true;
}
确保该变量为真。
[EDIT3]
帮助澄清我的问题:http://s14.postimg.org/6sajsb5tp/ellipse.png
[Edit4]
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();
}
}