xamarin.forms - 如何自定义 SfComboBox 的选中值显示模板
问题描述
我无法调整 a 的项目显示样式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>
数据对象的类(注意:生成此类。因此我无法修改类结构):
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 来完成这个。我已经尝试过DisplayMemberPath
了,combobox:SfComboBox
没有成功。请记住:Country
对象的Name
属性是Dictionary
.
解决方案
我们已经分析了您的查询,目前我们在 SfComboBox 中不支持 DisplayMemberPath 的字典,我们已经记录了对此的功能请求,您可以从下面的链接跟踪功能的状态
反馈门户: https ://www.syncfusion.com/feedback/22399/provide-dictionary-datatype-support-for-displaymemberpath
请投下你的一票,让它发挥作用。我们将根据需求对每个版本的功能进行优先级排序,并且我们没有立即实施该功能的计划,因为我们已经承诺了已经计划好的工作。因此,此功能将在我们即将发布的任何版本中提供。
推荐阅读
- node.js - 可以使用 Kerberos SSO 为主机创建-react-app / WebpackDevServer 代理吗?
- scala - 在 spark 数据框中使用案例类的好处
- c# - Python 中 MQTT over TLS 验证错误(C# 和 Mqtt.fx 中没有错误)
- mysql - 如何获取 MySql 选择/加入查询中每个名称的最新值?
- ionic-framework - 单击日历字段时想要禁用离子应用程序中的键盘
- python - Pyside - 使用 args 时无法连接信号
- ios - iOS Siri 快捷方式:我可以隐藏 Siri 上的操作按钮吗?
- php - 空数组在 Laravel 刀片中不会显示为空
- javascript - 如何使用 jQuery 或 JavaScript 添加元素?
- mysql - Mysql连接主机每次都在docker容器中更改,为什么?