Ich hab leider ein weiteres Problem.
Wenn ich ein Objekt bewegen will mit Canvas.Setleft(poly, pos_x) wird das Objekt nicht neu gezeichnet.
Es erhält zwar die pos_x aber das Canvas zeichnet es nicht, außer ich füge es neu mit MyCanvas.Children.Add hinzu.
Dann allerdings ist das Polygon 2 mal vorhanden.
Main Class:
test Class:
Code:
class test
{
private double pos_x;
private double pos_y;
public test()
{
}
public Polygon Paint()
{
PointCollection points = new PointCollection();
points.Add(new Point(10, 0));
points.Add(new Point(0, 10));
points.Add(new Point(20, 10));
LinearGradientBrush brush = new LinearGradientBrush();
brush.StartPoint = new Point(0.5, 0);
brush.EndPoint = new Point(0.5, 1);
brush.GradientStops.Add(new GradientStop(Color.FromRgb(255, 0, 0), 0.0));
brush.GradientStops.Add(new GradientStop(Color.FromRgb(0, 255, 0), 0.0));
Polygon poly = new Polygon();
poly.Fill = brush;
poly.Points = points;
Canvas.SetTop(poly, pos_y);
Canvas.SetLeft(poly, pos_x);
return poly;
}
public void move(double x)
{
pos_x = x;
Paint();
}
}
So wird es natürlich gezeichnet aber eben immer nebeneinander und selbst mit MyCanvas.Children.Remove(tester.Paint()); verschwindet das Polygon nicht.
Die möglichkeit MyCanvas.Children.clear() würde funktionieren nur will ich später mehrere Objekt auf dem Bildschirm haben. MUSS ich wirklich bei jeder bewegung ALLE objekte neu zum Canvas hinzufügen?
Das funktioniert:
Ich hoffe ihr könnt mir weiterhelfen :-)