changing ellipse color based on hand position RRS feed

  • Question

  • Hello,

    I'm new to C#, WPF, and XAML. I'm trying to change the fill color of an ellipse based on the height of a hand's position.

    First off, I don't get how to even change the color.


     private void SetEllipseProperties(FrameworkElement ellipse, Joint joint)
                var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);
                // change position
                Canvas.SetLeft(ellipse, scaledJoint.Position.X);
                Canvas.SetTop(ellipse, scaledJoint.Position.Y);
                //change color
                ellipse.Fill = someColorFunction(scaledJoint.Position.Y);

    but Fill from above gives me this error:


    "System.Windows.FrameworkElement' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'System.Windows.FrameworkElement' could be found (are you missing a using directive or an assembly reference?)"

    I thought Fill is a property of the ellipse class that I can just change. Can anyone help me out?

    Thanks for being patient,



    Friday, September 2, 2011 8:33 AM


  • Hi Michael,


    Without wanting to sound too condescending, Google is your friend. A search for "WPF set the colour of an ellipse" returned many results, and the first one there from MSDN demonstrates exactly how to do it halfway down the page.

    Apart from that, the premise of your code is right - every time the Skeleton frame event fires, you would call SetEllipseProperties, then all of the updating should work as you expect with what you've posted.



    Friday, September 2, 2011 8:45 AM