我有个问题。我有一个 Ellipse: ellipse1 在 Canvas: canvas1 内。当我点击 ellipse1 时,它的填充从 White 变为 PaleVioletRed。当我单击 canvas1 的另一部分时,椭圆将移到那里。这行得通。
当我再次单击 ellipse1 时,它的填充颜色不会改变。
怎么了?...
我有这个 ellipse1 的 XAML 代码:
<Ellipse Height="35" HorizontalAlignment="Left" Name="ellipse1" Stroke="Black" VerticalAlignment="Top" Width="70" Fill="White" StrokeThickness="3" Canvas.Left="71" Canvas.Top="70" MouseDown="pion_alb1_md"/>
这是 C# 部分:
private void pion_alb1_md(object sender, EventArgs e)
{
if (ellipse1.Fill == Brushes.White)
{
ellipse1.Fill = Brushes.PaleVioletRed;
}
else
{
ellipse1.Fill = Brushes.White;
}
}
这是 canvas1 的 XAML 代码:
<Canvas Name="piese_canvas" MouseDown="mouse_down_canvas_piese" Background="#43FCFFEB">
.......
</Canvas>
...这是 canvas1 的 C# 部分:
private void mouse_down_canvas_piese(object sender, EventArgs e)
{
if (ellipse1.Fill == Brushes.PaleVioletRed)
{
Point c = Mouse.GetPosition(piese_canvas);
if ((c.X > 81) && (c.Y < 311) && (c.X <160) && (c.Y >191))
{
Canvas.SetLeft(ellipse1, 72);
Canvas.SetTop(ellipse1, 241);
ellipse1.Fill = Brushes.White;
Canvas.SetLeft(ellipse5, -12);
Canvas.SetTop(ellipse5, 241);
}
}
}