In this tutorial series, we will see how to create a CardView in .Net MAUI using Border control. In .NET Maui provided Microsoft....

.Net MAUI - Card Views using Border Control .Net MAUI - Card Views using Border Control

.Net MAUI - Card Views using Border Control

.Net MAUI - Card Views using Border Control

In this tutorial series, we will see how to create a CardView in .Net MAUI using Border control. In .NET Maui provided Microsoft.Maui.Graphics library which provide us a consistent UI drawing API based on native graphics engines, thus making it easier for us to add borders, corners customisations, and shadows for most of the controls and layout contained in .NET MAUI. The new Border Control allows us to add Borders to a single element as a content (can be both a control and a Layout). This brings us a very flexible behavior to control of each corners: top-left, top-right, bottom-left, bottom-right, with our user interface, some of those cases can be adding the border to a button and rounding the upper left and lower right corners.


Quick Links:


Project Setup:

  • Launch Visual Studio 2022, and in the start window click Create a new project to create a new project.
  • In the Create a new project window, select MAUI in the All project types drop-down, select the .NET MAUI App template, and click the Next button:
  • In the configure your new project window, name your project, choose a suitable location for it, and click the Next button:
  • In the Additional information window, click the Create button:
  • Once the project is created, we can able to see the Android, iOS, Windows and other running options in the toolbar. Press the emulator or run button to build and run the app

Implementation:

  • Open the MainPage.xaml file and add the following border control. Border Properties
    Stroke Sets the color that the border will take on.
    StrokeThickness It’s the thickness (width) of the Border.
    StrokeDashOffset It’s the distance within the dash pattern.
    StrokeDashArray Collection of values, which is responsible for specifying the Dash pattern and the spaces used for the border to implement.
    StrokeLineCap Defines the start and end stroke that the border will have. For the stroke shape, it receives the following values: Flat, Round, and Square.
    StrokeMiterLimit Limit on the ration of the miter length to half of the stroke thickness.
  • We also having the StrokeShape property, which allows to modify the shape of the Stroke based on a Shape (the one you want), in addition to this Shape you can modify the edges as you need.
  • We also add shadow property to apply in CardView.
  • The final output will be like below when we come all the above properties come together.

Full Code:

Download Code:

You can download the code from GitHub. If you have any doubts, feel free to post a comment. If you liked this article, and it is useful to you, do like, share the article & star the repository on GitHub.

0 comments:

Please Comment about the Posts and Blog