wpf 调试错误输出 System.WIndows.Data 错误 25

标签 wpf debugging combobox

我有一个自定义样式的组合框,效果很好。它被放置在用户控件内并绑定(bind)到数据结构。我使用 DisplayMemberPath 在 Combobox TextBox 中只显示一个元素。 ComboBox Style 取自 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"!
你有解决这个问题的想法吗?

最佳答案

您不能同时设置 DisplayMemberPathItemTemplate同时。
DisplayMemberPath用于告诉 ItemsControl 在显示对象时显示哪个属性。如果您已经传递了自定义 ItemTemplate,则设置此字段没有意义。 ,因为您可以选择如何在该 ItemTemplate 中显示对象。

由于 MSDN 中的默认 Combobox 样式也设置了 ItemTemplate,这可能是错误的原因。

关于wpf 调试错误输出 System.WIndows.Data 错误 25,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15654935/

相关文章:

.net - 我需要做什么才能使需要完全信任的 WPF 浏览器应用程序 (XBAP) 在 Windows 7 上运行?

wpf - 在 WPF 中使用数据绑定(bind)启动动画

wpf - 使用Xceed PropertyGrid

node.js - 如何在meteor上远程调试服务器代码?

JavaFX 组合框,单击的项目

c# - 在 WPF 图像上禁用抗锯齿

c++ - gdb python编程: how to write code that will set breakpoints to every method of a C++ class?

c++ - Boost Geometry/intersection() 似乎返回不一致的结果

java - 如何在java中单击按钮时显示组合框?

WPF 对 Automation Peer API 的递归调用无效