Xceed Toolkit for .NET Maui v2.0 Documentation
Xceed.Maui.Toolkit Assembly / Xceed.Maui.Toolkit Namespace / ComboBox Class / ItemTemplate Property
Example


In This Topic
    ItemTemplate Property (ComboBox)
    In This Topic
    Gets or sets the DataTemplate that will be used to display the items appearing in the ComboBox's Popup.
    Syntax
    'Declaration
     
    
    Public Property ItemTemplate As DataTemplate
    'Usage
     
    
    Dim instance As ComboBox
    Dim value As DataTemplate
     
    instance.ItemTemplate = value
     
    value = instance.ItemTemplate
    public DataTemplate ItemTemplate {get; set;}
    Remarks
    Note that this property cannot be used if the DisplayMemberPath property is also used; it is only possible to use either the ItemTemplate or the DisplayMemberPath property at any given time.
    Example

    In the following example, the ItemsSource uses a binding on the UserObjects property of the ContentPage, which is a collection of objects representing various persons.

    Each object, meaning each person in the collection, is represented in the ComboBox as a horizontal stack layout containing two horizontal labels; the second label is using a binding on the Name property, which is found within each object & represents the name of the person associated with said object, in order to get the names of the persons in the collection.

    <xctk:ComboBox WidthRequest="200"
                   ItemsSource="{Binding UserObjects, Source={x:Reference _contentPage}}">
      <xctk:ComboBox.ItemTemplate>
        <DataTemplate>
          <HorizontalStackLayout Margin="5"
                                 Background="Yellow">
            <Label Text="This is"
                   Margin="5"/>
            <Label Text="{Binding Name}"
                   Margin="5"/>
          </HorizontalStackLayout>
        </DataTemplate>
      </xctk:ComboBox.ItemTemplate>
    </xctk:ComboBox>
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also