我有一个自定义样式的组合框,效果很好。它被放置在用户控件内并绑定到数据结构。我使用 DisplayMemberPath 仅显示组合框文本框中的一个元素。 ComboBox 样式取自 MSDN,并被多次使用。所以这里就不显示了。
<UserControl x:Class="wpf.projext1.MyComboBox"
x:Name="MyControl"
...
<ComboBox Style="{StaticResource ComboBoxStyle}"
Text="{Binding ElementName=MyControl, Path=Text}"
IsEditable="True"
IsTextSearchEnabled="False"
StaysOpenOnEdit="True"
ItemsSource="{Binding ElementName=MyControl, Path=MyItemsSource}"
DisplayMemberPath="Name"
</ComboBox
我在输出窗口中收到以下烦人的错误消息:
System.Windows.Data Error: 25 : Both 'ContentTemplate' and 'ContentTemplateSelector' are set; 'ContentTemplateSelector' will be ignored. ComboBoxItem:'ComboBoxItem' (Name='')
如果我省略了
DisplayMemberPath="Name"
...没有显示有关错误 25 的调试输出。但我绝对需要 DiplayMemberPath="Name"!
你有办法解决这个问题吗?
您不能同时设置两者DisplayMemberPath
and ItemTemplate
同时。
DisplayMemberPath
用于告诉 ItemsControl 在显示对象时显示哪个属性。如果您已经传递了自定义字段,则设置此字段是没有意义的ItemTemplate
,因为你可以选择how显示该 ItemTemplate 中的对象。
由于 MSDN 中的默认 Combobox 样式也设置了 ItemTemplate,因此这可能是错误的原因。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)