组合框显示成员路径上的 StringFormat [英] StringFormat on Combobox Displaymemberpath
本文介绍了组合框显示成员路径上的 StringFormat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 ComboBox (WPF) 的 DisplayMemberPath 属性上使用 StringFormat.但我不知道这是否可能.有人能帮我出出主意吗.
I am trying to use StringFormat on DisplayMemberPath property of a ComboBox (WPF). But i don't know even if this is possible. can someone help me with some ideas.
我正在尝试做这样的事情:
I am trying to do something like this:
<ComboBox DisplayMemberPath="{Binding Path=MyDateField, StringFormat={}{0:dd/MM/yyyy}}" Name="CmbName" Width="120" />
但它不起作用...
感谢所有
推荐答案
您可以简单地使用 ItemStringFormat
属性.
You can simply use the ItemStringFormat
property.
注意:这仅在 IsEditable
设置为 False
<ComboBox ItemsSource="{Binding YourItems}"
DisplayMemberPath="MyDateField"
ItemStringFormat="{}{0:dd/MM/yyyy}"
IsEditable="False" />
这篇关于组合框显示成员路径上的 StringFormat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文