如何自定义SfComboBox的选中值显示模板

How to customize the SfComboBox's selected value display template

我无法调整 SfComboBox 的项目显示样式。组合框使用 DataSource。似乎给定的 ItemTemplate 只影响选项列表,而不影响显示所选值的实际字段。

问题(之前选择了“Deutschland”选项,但显示的是“de”。我希望使用相同的字符串):

我各自的样本 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>

数据对象的class(注意:生成这个class。因此我不能修改class结构):

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;}
    
    }

我的目标 是组合框的字段使用与选项项相同的格式(例如,使用国家的德国名称)。如果可能的话,我想用简单的 XAML 来完成这个。我已经在 combobox:SfComboBox 上尝试过 DisplayMemberPath 但没有成功。请记住:Country 对象的 Name 属性 是 Dictionary.

我们已经分析了您的查询,目前我们在 SfComboBox 中没有对 DisplayMemberPath 的字典支持,我们已经记录了对此的功能请求,您可以从下方跟踪该功能的状态 link

反馈门户: https://www.syncfusion.com/feedback/22399/provide-dictionary-datatype-support-for-displaymemberpath

请投出您的一票以使其有效。我们将根据需求对每个版本的功能进行优先排序,并且我们没有立即实施此功能的计划,因为我们已经承诺进行已经计划好的工作。因此,此功能将在我们即将发布的任何版本中提供。