Naryoril
Naryoril

Reputation: 601

Difference between .NET MAUI Border and Frame

What's the functional difference between a Border and a Frame in .NET MAUI?

The summary of a Border according to the documentation is

The .NET Multi-platform App UI (.NET MAUI) Border is a container control that draws a border, background, or both, around another control. A Border can only contain one child object. If you want to put a border around multiple objects, wrap them in a container object such as a layout.

And the summary of a Frame is as follows

The .NET Multi-platform App UI (.NET MAUI) Frame class is used to wrap a view or layout with a border that can be configured with color, shadow, and other options. Frames can be used to create borders around controls but can also be used to create more complex UI.

Sounds like they both do the same thing to me: drawing a border around another view (whether that's a layout or a single control doesn't matter). So why are there 2 different views? How do I decide which one to use?

Upvotes: 28

Views: 15862

Answers (1)

Gerald Versluis
Gerald Versluis

Reputation: 33983

Edit: as of .NET 9 Frame is actually marked obsolete and Border is recommended instead.

I think this is due to the history of .NET MAUI. The Frame is a control that is in Xamarin.Forms. I'm not sure if it was ever intended to be the control to put a border around something, but since it was the only control that could do a shadow and border for a long time, a lot of people wrapped their controls in a Frame.

However, now with .NET MAUI there is the opportunity to fix some historical tech debt. That is why Border was introduced which is much more flexible. With Border you can give each corner an individual corner radius for instance. And instead of just a solid color you can give the Border a gradient.

So from a functional perspective the Border has more options and will probably outlive the Frame although there is no indication that Frame is going anywhere anytime soon.

There is probably more little differences here and there. Based on nothing more than a gut feeling I would think Border performs better, but I have no data to back that up.

Hope this makes it a bit more clear.

Upvotes: 46

Related Questions