0

I am making a pool game as my project. I am having troubles of declaring the ellipse image to link with the class so that I can use it with the physics engine later on. I was left with this code to finish and I've already research for 5 hours just to figure out this problem.


At XAML

<Ellipse Canvas.Left="314" Canvas.Top="305" Height="35" Name="Ball1" Stroke="Black" Width="35" StrokeThickness="0.01">
            <Ellipse.Fill>
                <ImageBrush ImageSource="/FYPJ;component/Images/Balls/1.png" />
            </Ellipse.Fill>
        </Ellipse>

Class

  public Point Position { get; set; }
  public int BallNum
    {
        get
        {
            return ballNum;
        }
        set
        {
            if (value <= 7)
                IsSolid = true;
            else
                IsSolid = false;
            ballNum = value;
        }
    }
public Ball(int ballNumber, Point position)
    {
        this.BallNum = ballNumber;
        this.Position = position;
        // TODO: rember to add physics behavior later
    }

At XAML.cs

private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        // init ball position
        foreach (Ball ball in balls)
        {
            Ellipse ballImage = this.GetBallImage(ball);
            Console.WriteLine("ball " + ball.BallNum); // For Testing according to my teacher
            ball.Position.X = ; // Unfinished Code
            ball.Position.Y = ; // Unfinished Code


        }

}

If you think there are still code that I missed out on this question. Feel free to comment it out. Thank you.

Miguel
  • 63
  • 2
  • 2
  • 9
  • You have problem in code behind to obtain ellipse property defined in xaml? [Click](http://stackoverflow.com/q/974598/1997232). – Sinatr Oct 08 '14 at 13:43
  • Yes. I was told to get the coordinates of the ellipse image in order for me to define the ellipse image to the class. I'm not really sure how to do it. – Miguel Oct 08 '14 at 14:07
  • Give ellipse a name in xaml: ` – Sinatr Oct 08 '14 at 14:13
  • I am having this type of error: An object of a type convertible to 'System.Windows.Point' is required – Miguel Oct 09 '14 at 03:37
  • Try `ball.Position = new Point((double)ellipse.GetValue(Canvas.LeftProperty), (double)ellipse.GetValue(Canvas.TopProperty));` – Sinatr Oct 09 '14 at 07:05

0 Answers0