I would like to redefine a class of the core wpf API (UIElement), I don’t want to inherit a class.
In have a project on the MS Kinect, I’ve re-implemented cursors mapped with the user’s skeleton’s hand. I’ve implemented similar event to those that the mouse raised (enter an elements, leave an element…). I want that all elements inheriting from UIElement to get some attached properties:
KinectCursorEnter, KinectCursorMove...
and some Properties:
public bool IsKinectLeftCursorOver { get; set; }
public bool IsKinectLeftCursorDirectlyOver { get; set; }
public bool IsKinectRightCursorOver { get; set; }
public bool IsKinectRightCursorDirectlyOver { get; set; }
public bool IsKinectLeftCursorCaptured { get; set; }
...
I know there’s a lot ways to mess things up if I change such a class, but that’s at this level that I want to add thoses properties. (UIElement already implement stuff such as MouseEnter, StylusEnter…). The Kinect is an input device as any other (mouse, stylus, keyboard…)
I’ve try:
- To inherit UIElement and add the feature , but then I would have to
reimplement all the Classes.
I’ve take a look:
- If there’s such a thing as Ruby’s open classes
- If I can use extension (link)
- If I can use in any way Adapter pattern
So far I’m using use:
- An interface and I redefine all element: I have a
KinectButtonthat
inherit fromButtonand implementsIKinectInputElementbut I can’t do that for some class which aresealed(Rectangle, Ellipse…)
I thing I a few months (years?) MSFT will implement those kind a Properties and method in Wpf API. But for now I need a way around.
PS: I don’t want to control the mouse with one of the hand of the user. there is one mouse, I want to have two cursors. and I have events such as : KinectLeftCursorEnter, KinectRightCursorEnter and so on..
You can use Extension Methods to extend the class.