How to select the non-list item in WinUI ComboBox at load time?
This article will help to explain how to show the non-list item in the WinUI SfComboBox.
In SfComboBox, we have a SelectionChanging event that helps to decide whether to show the non-list item in the SfComboBox by using the event args value. By setting the AllowDetachedSelection as True, you can show the value at load time. The following example shows how to set the property using the event.
C#
comboBox.SelectionChanging += OnComboBoxSelectionChanging;
private void OnComboBoxSelectionChanging(object sender, Syncfusion.UI.Xaml.Editors.ComboBoxSelectionChangingEventArgs e)
{
var newItems = e.AddedItems;
foreach (var item in newItems)
{
var viewModel = combobox.DataContext as SocialMediaViewModel;
if (item is SocialMedia)
{
if (!viewModel.SocialMedias.Contains(item as SocialMedia))
e.AllowDetachedSelection = true;
}
}
}
XAML
<editors:SfComboBox x:Name="comboBox"
Width="250"
TextMemberPath="Name"
DisplayMemberPath="Name"
ItemsSource="{Binding SocialMedias}"
SelectionChanging="OnComboBoxSelectionChanging" />
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxNon-listItem.zip
Conclusion
I hope you enjoyed learning how to select the non-list item at load time in WinUI ComboBox.
You can refer to our WinUI ComboBox feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the Licence and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forum, Support portal, or feedback portal. We are always happy to assist you!