Question

It is a short question. For example I want to add a field double weight to my ellipse. How can I do this?

Sorry for 2 copies of comment

Was it helpful?

Solution 2

For this kind of situation, I create a class where one attribute is the Ellipse and the other attributes are the attributes I want to add to the ellipse class. This is a bit dirty but it allows to have a class that contains all the Ellipse features as well as my additional attributes.

class WeightedEllipse
{
public Ellipse ellipse;
public double weight;

public WeightedEllipse(double weight)
    {
      this.ellipse=new Ellipse();
      this.weight=weight;
    }
}

OTHER TIPS

If you are referring to System.Windows.Shapes.Ellipse then you cannot extend the class - it is sealed. However you could use a custom attached property to add your weight information.

Something along the lines of the following: (in a "HelperClass")

public static readonly DependencyProperty WeightProperty = DependencyProperty.RegisterAttached(
  "Weight",
  typeof(double),
  typeof(HelperClass),
  new FrameworkPropertyMetadata(0)
);

public static void SetWeight(Ellipse element, double value){
  element.SetValue(WeightProperty, value);
}

public static double GetWeight(Ellipse element) {
  return (double)element.GetValue(WeightProperty);
}

and then later

HelperClass.SetWeight(ellipseInstance, 42d)

If Ellipse is your own class (and not a DependencyObject), then of course extending should not be an issue and we would require more information to help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top