Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is WPF Decorator class useful?

I need to create control to draw border around its child. So, I have created class and derived it from Decorator:

class RoundedBoxDecorator : Decorator
{
    protected override Size ArrangeOverride(Size arrangeSize)
    {
        //some source
    }

    protected override void OnRender(DrawingContext dc)
    {
        //some source
    }
}

It works fine, but I have some doubts about using Decorator as ancestor. I have found in MSDN that there are no special methods or properties in it, only derived from its ancestors (UIElement or FrameworkElement). ArrangeOverride and OnRender are also derived.

So, what for Decorator class was designed and does it makes sense to use it? Or I can derive from FrameworkElement?

like image 729
darja Avatar asked Mar 27 '10 14:03

darja


1 Answers

Besides what it inherits from FrameworkElement, the Decorator class implements a Child property (of type UIElement), as well as implementing the IAddChild interface. Thus Decorator is the most primitive element that can contain another element.

Is there a reason you were not able to use a Border element (which inherits from Decorator) to create the border around the child element?

like image 69
Daniel Pratt Avatar answered Nov 10 '22 12:11

Daniel Pratt