Can I nest ItemTemplates?

I have a need for a control of a sfComboBox that use sfChips as it's elements.
Here is my sample code.

Supplies.DataSource = viewModel.SuppliesList;
Supplies.ItemTemplate = new DataTemplate(() =>
{
    SfChip chip = new SfChip();
    chip.ControlTemplate = new ControlTemplate(() =>
    {
        StackLayout sl = new StackLayout() { Orientation = StackOrientation.Horizontal };
        var optionIcon = new Image { HeightRequest = 20, WidthRequest = 20, HorizontalOptions = LayoutOptions.Start, };
        optionIcon.SetBinding(Image.SourceProperty, "Image");
        var displayName = new Label { VerticalTextAlignment = TextAlignment.Center, HorizontalOptions = LayoutOptions.Start, Style = (Style)Application.Current.Resources["DataLabel"] };
        displayName.SetBinding(Label.TextProperty, "Name");
 
        sl.Children.Add(optionIcon);
        sl.Children.Add(displayName);
 
        return sl;
    });
 
    return chip;
});

When I run this code, I get a sfComboBox that has the proper number of elements, that are just blank sfChips.

Any ideas or suggestions?

Thanks!


3 Replies 1 reply marked as answer

SS Suganya Sethuraman Syncfusion Team May 6, 2021 11:02 AM UTC

Hi Jesse,

Greetings from Syncfusion.

We have analyzed your query. ControlTemplate is not supported by SfChip. Please use SfChip.Content instead.

Please have a sample for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboChip2053964008

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Marked as answer

JK Jesse Knott May 10, 2021 12:12 AM UTC

Thanks! I'll take a look and implement the recommended code!
Cheers!


SS Suganya Sethuraman Syncfusion Team May 10, 2021 06:02 AM UTC

Hi Jesse,

Thanks for the update.

Please let us know if you have any other queries.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon