WPF IEnumerable<T> vs IQueryable<T> as DataSource

冷暖自知 提交于 2019-12-08 13:29:26

问题


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

and

public interface IEnumerable<T> : IEnumerable

so where is the problem?


回答1:


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}" … />


来源:https://stackoverflow.com/questions/1226036/wpf-ienumerablet-vs-iqueryablet-as-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!