ListView DisplayMemberPath模板错误? [英] ListView DisplayMemberPath Template Bug?
问题描述
我想知道是否有人对此问题有所了解.看来此处为ListViewItem提供的默认模板不支持 ListView的> DisplayMemberPath
.
示例
< ListView ItemsSource ="{Binding SomeSource}" DisplayMemberPath ="Name"/>
将不会按预期显示项目.如果将 GridViewRowPresenter
替换为 ContentPresenter
,它将起作用.因此,我编写一个可以正常工作的模板的解决方法是为 DisplayMemberPath
和 Value ="
编写一个DataTrigger,然后将模板设置为包含GridViewRowPresenter的模板.如果我不这样做,使用ItemsPresenter的GroupStyle将不起作用.
我的问题:这是一个错误还是我做错了什么?
我在此处
DisplayMemberPath
属性实际上是一个快捷方式,它将告诉WPF创建默认项目模板,而该模板仅包含 TextBlock
,且文本绑定到 DisplayMemberPath
如果除了设置 DisplayMemberPath
之外还覆盖了项目模板,则实际上是在覆盖 DisplayMemberPath
为您创建的模板,因此该属性将变得无用.
I am wondering if anyone know something about this issue. It seems like the default template provided here for ListViewItem does not support DisplayMemberPath
of ListView.
Example
<ListView ItemsSource="{Binding SomeSource}" DisplayMemberPath="Name" />
will not display the items as expected. It will work if I replace the GridViewRowPresenter
with a ContentPresenter
. So my workaround to write a fully working template is to write a DataTrigger for DisplayMemberPath
with Value=""
and there I set the Template to a Template containing the GridViewRowPresenter. If I will not do this a GroupStyle with ItemsPresenter will not work.
My Question: Is this a bug or am I doing something wrong?
I asked a similar question here
The DisplayMemberPath
property is actually a shortcut that will tell WPF to create the default item template with nothing more than a TextBlock
with it's Text bound to whatever field is in DisplayMemberPath
If you overwrite the item template in addition to setting DisplayMemberPath
, then you are essentially overwriting the template that DisplayMemberPath
created for you, so that property becomes useless.
这篇关于ListView DisplayMemberPath模板错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!