我遇到問題。我有一個位於Canvas:canvas1中的Ellipse:ellipse1。 當我點擊ellipse1時,它的填充從白色變成了PaleVioletRed。當我點擊canvas1的另一部分時,橢圓將移動到那裏。這工作。Ellipse的MouseDown不起作用
當我再次單擊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);
}
}
}
啊,我沒有看到這個!哎呦。 – 2012-07-19 13:03:13