AutoSizing in .NET MAUI ComboBox
21 Jul 20264 minutes to read
Prerequisites
Before using the SfComboBox, ensure the following NuGet package is installed in your .NET MAUI project:
Syncfusion.Maui.Inputs
For a step-by-step setup, refer to the Getting Started documentation.
EnableAutoSize
The EnableAutoSize property in the ComboBox control automatically adjusts the editor height to fit the selected tokens, so the control grows to display all wrapped tokens without scrolling. It is a bool property and the default value is false.
To make AutoSizing take effect, configure the ComboBox with the following:
-
SelectionMode set to
Multiple. -
MultiSelectionDisplayMode set to
Token(default). -
TokensWrapMode set to
Wrap.
<editors:SfComboBox x:Name="comboBox"
ItemsSource="{Binding SocialMedias}"
SelectionMode="Multiple"
MultiSelectionDisplayMode="Token"
MaxDropDownHeight="250"
DisplayMemberPath="Name"
TextMemberPath="Name"
Placeholder="Enter Media"
TokensWrapMode="Wrap"
EnableAutoSize="True">
<editors:SfComboBox.BindingContext>
<local:SocialMediaViewModel />
</editors:SfComboBox.BindingContext>
</editors:SfComboBox>SocialMediaViewModel socialMediaViewModel = new SocialMediaViewModel();
SfComboBox comboBox = new SfComboBox
{
ItemsSource = socialMediaViewModel.SocialMedias,
SelectionMode = ComboBoxSelectionMode.Multiple,
MultiSelectionDisplayMode = ComboBoxMultiSelectionDisplayMode.Token,
MaxDropDownHeight = 250,
DisplayMemberPath = "Name",
TextMemberPath = "Name",
Placeholder = "Enter Media",
TokensWrapMode = ComboBoxTokensWrapMode.Wrap,
EnableAutoSize = true,
};// ViewModel
public class SocialMediaViewModel
{
public ObservableCollection<SocialMedia> SocialMedias { get; set; }
public SocialMediaViewModel()
{
this.SocialMedias = new ObservableCollection<SocialMedia>
{
new SocialMedia { Name = "Facebook", ID = 0 },
new SocialMedia { Name = "Google Plus", ID = 1 },
new SocialMedia { Name = "Instagram", ID = 2 },
new SocialMedia { Name = "LinkedIn", ID = 3 },
new SocialMedia { Name = "Skype", ID = 4 },
new SocialMedia { Name = "Telegram", ID = 5 },
new SocialMedia { Name = "Twitter", ID = 6 },
new SocialMedia { Name = "WhatsApp", ID = 7 },
new SocialMedia { Name = "YouTube", ID = 8 }
};
}
}
public class SocialMedia
{
public string Name { get; set; }
public int ID { get; set; }
}
NOTE
If
EnableAutoSizeis set totruewithoutSelectionModeasMultipleorTokensWrapModeasWrap, the AutoSizing behavior is ignored and the editor height remains fixed.