WPF IEnumerable< T>与IQueryable< T>作为数据源 [英] WPF IEnumerable<T> vs IQueryable<T> as DataSource
问题描述
我有一个 WPF ListView ,并将其绑定到 IEnumerable< T>
集合。
一切正常,但是当我将其绑定到 IQueryable< T>
集合时,列表中不再有任何项目。为什么?它不是可观察的还是什么?
当我查看定义时:
I have a WPF ListView and I bind it to a IEnumerable<T>
collection.
Everything works fine, but when I bind it to the IQueryable<T>
collection, there are no items in list anymore.. Why? Is it not observable or what?
When I look at the definition:
public interface IQueryable<T> : IEnumerable<T>, IQueryable, IEnumerable
和
public interface IEnumerable<T> : IEnumerable
那么问题出在哪里?
推荐答案
正如您正确指出的那样,这些类型兼容,应该可以使用。在绑定中打开调试并尝试。也许输出将是一个线索。除了您要绑定的类型之外,还有其他可能。
It should work, as you correctly point out, these types are compatible. Turn on debugging in your binding and try it. Maybe the output will be a clue. It's likely something else besides the type you are binding to.
无论如何,这里是代码。将其放入视图中,然后在加载视图时观看输出窗口。如果是希腊文,则只需使用输出窗口中的输出来编辑帖子。
Anyway, here's the code. Put this in and watch your output window when your view loads. If it's Greek to you, just edit your post with the output from your output window.
<Window …
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
/>
<TextBlock Text="{Binding Path=Caption, diagnostics:PresentationTraceSources.TraceLevel=High}" … />
这篇关于WPF IEnumerable< T>与IQueryable< T>作为数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!