How to use Picker as country Picker in .NET MAUI Picker (SfPicker)?
In this article, you will learn how to transform the Syncfusion® .NET MAUI Picker control into a versatile country selector. This demonstration guides you through initializing and customizing the picker, including setting headers, footers, and item sources.
XAML:
Initialize the SfPicker control, and use the HeaderView and FooterView properties of SfPicker to customize the picker.
<picker:SfPicker x:Name="picker">
<picker:SfPicker.HeaderView>
<picker:PickerHeaderView Text="Select a Country" Height="40">
</picker:PickerHeaderView>
</picker:SfPicker.HeaderView>
<picker:SfPicker.FooterView>
<picker:PickerFooterView Height="40">
</picker:PickerFooterView>
</picker:SfPicker.FooterView>
</picker:SfPicker>
C#:
Set the ItemSource property of the PickerColumn class as illustrated in the following code to bind the item source to the picker.
ObservableCollection<object> countryName = new ObservableCollection<object>();
countryName.Add("UnitedStates");
countryName.Add("Qatar");
countryName.Add("India");
countryName.Add("Germany");
countryName.Add("Spain");
countryName.Add("Malaysia");
countryName.Add("Netherlands");
countryName.Add("Mexico");
countryName.Add("Brazil");
PickerColumn pickerColumn = new PickerColumn()
{
ItemsSource = countryName,
SelectedIndex = 3,
};
this.picker.Columns.Add(pickerColumn);
Output:
Download the complete sample from GitHub.
Conclusion:
I hope you enjoyed learning how to use Picker as Country Picker in the .NET MAUI Picker (SfPicker).
Refer to our .NET MAUI Picker feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Picker documentation to understand how to present and manipulate data.
Check out our .NET MAUI 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 .NET MAUI Picker and other .NET MAUI components.
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!