Draw border only at the bottom of a Xamarin Button

영훈 정 281 Reputation points
2022-11-15T08:47:45.09+00:00

I have given the border property of the button and I want to make the border only the bottom. There seems to be a way to do it in renderer and a way to use Boxview in stacklayout. Is there a simple way to implement it?

I would appreciate it if you could provide an example.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,471 Reputation points Microsoft Vendor
    2022-11-16T05:30:20.497+00:00

    Hello,

    The best solution to this problem is to use the BoxView as the bottom border of the button.

    It works and is concise enough.

    On Xamarin.Forms, you can make the combination of Button and BoxView into a control by using ContentView for easy reuse.

       <ContentView.Content>  
           <StackLayout Orientation="Vertical"  
                    Spacing="0">  
               <Button Text="Click here"  
                   BorderColor="Transparent"  
                   BorderWidth="0" />  
               <BoxView HeightRequest="1"  
                    HorizontalOptions="FillAndExpand"  
                    VerticalOptions="EndAndExpand"  
                    Color="Blue" />  
           </StackLayout>  
       </ContentView.Content>  
    

    The Xamarin.Forms ContentView class is a type of Layout that contains a single child element and is typically used to create custom, reusable controls.

    Please refer to Xamarin.Forms ContentView to get more details.

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful