What is the recommended way to draw a .NET MAUI horizontal line in XAML?

dg2k 1,396 Reputation points
2023-02-27T06:41:11.1166667+00:00

I tried BoxView control element with a small height such as HeightRequest="1" but the BackgroundColor doesn't behave properly.

I also tried the Line shape element but this requires extra bindings as it doesn't fill the available space.

Is there a better way to add a separator line in XAML?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,582 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,926 Reputation points Microsoft Vendor
    2023-02-28T01:44:31.5366667+00:00

    Hello,

    I tried BoxView control element with a small height such as HeightRequest="1" but the BackgroundColor doesn't behave properly.

    The reason for this problem is that in BoxView, its color is controlled by Color instead of BackgroundColor.

    Color, of type Color, which defines the color of the BoxView.

    Please refer to BoxView to get more details.

    For instance, you could create a red separator line with the following code:

    <BoxView HeightRequest="1" Color="Red"/>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.