WPF Rectangle vs Border: which is better for performance?

There are times when I need a Border control or a Rectangle control. For example, when I implement a ControlTemplate and I already apply the layering technique (i.e. stack controls in the grid) and I donโ€™t need different RadiusX or RadiusY applied to corners.

However, when developing such ControlTemplates, sometimes I use several layers like Borders and Rectangles. So I realized that I probably should be aware of which control would have the least impact on the application. I see that their inheritance hierarchy diverges after FrameworkElement. And I also notice that Border is a Decorator control (I worked with Decorators, but I'm not sure how they work in relation to other controls). Can someone shed some light on

1) How could we draw some general conclusions about the impact of management performance based on a specific inheritance hierarchy?

2) How do decorators like Border execute relative to other controls?

3) In particular, regarding the border and rectangle, which works better?

+8
wpf wpf-controls
source share
1 answer

In my experience, WPF borders are a bit lighter, but more importantly, they represent a slightly different need, although they often turn out to be the same on the screen. If I am composing something that includes rectangles as part of what it is, then a rectangle is usually appropriate. If I want to emphasize something on the screen or indicate that the object has some other state, then I use the border. I often bind the color, thickness or visibility of this border to the state property of the model (or whatever in your case), but the essential difference is that the border is not part of the object. This is a way to simply highlight this object or to be visible.

Or, if this is some kind of thing already written, for example TextBox, and I add some color around it, it will usually be a border.

By observing this distinction, it helps your XAML tree better understand you and gives you code that is easier to maintain later.

0
source share

All Articles