Data Binding in .NET MAUI ComboBox
-
ItemsSource
(IEnumerable
)—Defines the collection of the items that will populate the control with data. -
DisplayMemberPath
(string
)—Defines the name of the property which will be visualized inside the drop-down list.
The DisplayMemberPath
is a property that lets the developer specify a particular property of the business object to be displayed. If DisplayMemberPath
is not set, the ComboBox will visualize the ToString
implementation of the business object.
To customize the content inside the input area when an item is selected and the DisplayMemberPath
property is not set, use the SelectionBoxTemplate
. The SelectionBoxTemplate
applies when the SelectionMode
is Single
and the control's IsEditable
property is set to false
.
Binding to a Complex Object
1. Define the ComboBox in XAML:
2. Add the telerik
namespace:
4. Add the ViewModel:
5. Set the binding context after InitializeComponent()
in the page's code behind: