How to make text wrap automatically in a custom dropdown for Android in .NET MAUI?

KarPreet 80 Reputation points
2025-01-16T07:16:49.1466667+00:00

I’m working on a .NET MAUI project using .NET MAUI 8 and targeting Android API Level 34 (Android 13).
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="34" />
What I’ve Tried:

  1. I ensured the layout for the dropdown uses HorizontalOptions = FillAndExpand.
  2. I tested with long text inside the dropdown, and it gets cut off on Android instead of wrapping to fit within the layout.
  3. A simple Label works fine and wraps text as expected, but the same behavior isn’t happening with the custom dropdown.

Here’s an example of the dropdown implementation:

<ScrollView x:Name="scrollView" VerticalOptions="Fill" HorizontalOptions="Fill"> <Grid Padding="20" x:Name="lytgridmain">
grdMain = new Grid()
 {
  
     RowDefinitions =
     {
         new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
     },
     ColumnDefinitions =
     {
         new ColumnDefinition { Width = new GridLength(7, GridUnitType.Star) },
         new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star) }
     }
 };
lytgridmain.Children.Add(grdMain);
drConnect = new CustomDropdown(this.absMain) 
{ 
   ClassId = "ConnectToBusOptions",
   Title = UIDisplayText,
   VerticalOptions = LayoutOptions.Center,
   HorizontalOptions = LayoutOptions.FillAndExpand
}; 
 
List<LOVModel> busOptionLov = new List<LOVModel> 
{ 
   new LOVModel { Text = "sample text every time", Value = "0", LOVID = "0" },
   new LOVModel { Text = "sample text connect everytime to the upstream", Value = "6", LOVID = "6" },
   new LOVModel { Text = "sample text connect everytime to the upstream example example", Value = "12", LOVID = "12" }
}; 
drConnect.ItemsSource = busOptionLov;grdMain.Add(drConnect, 1, 18);
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,877 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 47,926 Reputation points Microsoft Vendor
    2025-01-20T02:54:39.9433333+00:00

    Hello,

    Thanks for your feedback.

    If you add a Label directly to the Grid, the width will exceed the limit. This is a known issue.

    Workaround:

    If Grid is the necessary layout method, then you need to wrap the Label control with ContentView and set an arbitrary Magin property.

    You could refer to this documentation:

    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.


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.