Search code examples
xamarin.formscomboboxsyncfusion

How to customize the SfComboBox's selected value display template


I couldn't manage to adapt the item display style of a SfComboBox. The combobox is using a DataSource. It seems that the given ItemTemplate only affects the option list but not the actual field showing the selected value.

the issue (the option "Deutschland" was selected before, but "de" is displayed instead. I want that the same string is used):

enter image description here

sample of my respective Xaml:

<border:SfBorder Style="{DynamicResource SfBorderStyle}" Margin="5" BorderColor="{StaticResource primaryTint}" CornerRadius="8">
                        <combobox:SfComboBox x:Name="selectCountry" Margin="20,5,0,0" Style="{StaticResource DefaultComboBoxStyle}"
                                    Watermark="{x:Static p:Resources.SelectCountry}" SelectionChanged="countrySelectionChanged"
                                    SelectedItem="{Binding SelectedCountry}" DataSource="{Binding Countries}">
                            <combobox:SfComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Label Text="{Binding Name[de]}"/>
                                </DataTemplate>
                            </combobox:SfComboBox.ItemTemplate>
                        </combobox:SfComboBox>
                    </border:SfBorder>

the class of the data objects (note: this class gets generated. Thus I can't modifiy the class structure):

public class Country
    {
        [JsonProperty("code")]
        public string Code {get; set;}
    
        [JsonProperty("name")]
        public Dictionary<string, string> Name {get; set;}
    
        [JsonProperty("active")]
        public bool Active {get; set;}
    
        [JsonProperty("create_date")]
        public DateTime? CreateDate {get; set;}
    
        [JsonProperty("delete_date")]
        public DateTime? DeleteDate {get; set;}
    
        [JsonProperty("memo")]
        public string? Memo {get; set;}
    
        [JsonProperty("modify_date")]
        public DateTime? ModifyDate {get; set;}
    
    }

my goal is that the field of the combobox uses the same format as the option items do (eg. using the German name of the country). If possible I would like to accomplish this with plain XAML. I've already tried DisplayMemberPath on combobox:SfComboBox without success. Remember: a Country object's Name property is a Dictionary.


Solution

  • We have analyzed your query and currently we don’t have Dictionary support for DisplayMemberPath in SfComboBox and we have logged the feature request for this and you can track the status of the feature from below link

    Feedback portal: https://www.syncfusion.com/feedback/22399/provide-dictionary-datatype-support-for-displaymemberpath

    Please cast your vote to make it count. We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we have committed with already planned work. So, this feature will be available in any of our upcoming releases.