Articles in this section
Category / Section

How to work with .NET MAUI Expander (SfExpander) using C#?

5 mins read

You can create the .NET MAUI Expander application with SfExpander using C#. Below is a simple example of how to implement this in your project.

C#

   public partial class MainPage : ContentPage
   {
       StackLayout stack;
       SfExpander expander1, expander2;

       public MainPage()
       {
           InitializeComponent();

           stack = new StackLayout();
           // Expander 1
           expander1 = new SfExpander();
           // Expander header view
           var header1 = new Grid()
           {
               HeightRequest = 40
           };
           var headerLabel = new Label()
           {
               HorizontalTextAlignment = TextAlignment.Start,
               VerticalTextAlignment = TextAlignment.Center,
               Text = "Veg Pizza",

           };
           header1.Children.Add(headerLabel);
           expander1.Header = header1;

           // Expander content view
           var content1 = new Grid()
           {
               HeightRequest = 60
           };

           var contentLabel = new Label()
           {
               HorizontalTextAlignment = TextAlignment.Start,
               VerticalTextAlignment = TextAlignment.Center,
               HeightRequest = 60,
               Text = "Veg pizza is prepared with the items that meet vegetarian standards by not including any meat or animal tissue products.",
           };

           content1.Children.Add(contentLabel);
           expander1.Content = content1;

           // Expander 2
           expander2 = new SfExpander();
           // Expander header view
           var header2 = new Grid()
           {
               HeightRequest = 40
           };
           var headerLabel2 = new Label()
           {
               Text = "Non- Veg Pizza",
               HorizontalTextAlignment = TextAlignment.Start,
               VerticalTextAlignment = TextAlignment.Center,
           };
           header2.Children.Add(headerLabel2);
           expander2!.Header = header2;

           // Expander content view
           var content2 = new Grid()
           {
               HeightRequest = 60
           };

           var contentLabel2 = new Label()
           {
               HeightRequest = 60,
               Text = "Non-veg pizza is prepared by including the meat and animal tissue products.",
               VerticalTextAlignment = TextAlignment.Center,
               HorizontalTextAlignment = TextAlignment.Start,
           };
           content2.Children.Add(contentLabel2);
           expander2!.Content = content2;

           stack.Children.Add(expander1);
           stack.Children.Add(expander2);
           this.Content = stack;
       }
   }

Download the complete sample on GitHub

Conclusion

I hope you have enjoyed learning how to work with .NET MAUI Expander using C#.

You can refer to our .NET MAUI Expander feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.

Check out our components from the License and Downloads page for current customers. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied