简体   繁体   English

WPF ListView不显示可观察集合的内容

[英]WPF ListView not showing contents of Observable Collection

I have a listview in a WPF application which is supposed to display the contents of an observable collection. 我在WPF应用程序中有一个listview,应该显示可观察集合的内容。 I had it displaying in an older build, but in trying to make the listview update more often I changed the XAML quite a lot and after putting it back it now doesn't display anything, ever. 我在较旧的版本中显示了它,但是为了更频繁地进行列表视图更新,我对XAML进行了很多更改,放回XAML之后,它现在什么也不显示。

Here is the XAML: 这是XAML:

<TabItem GotFocus="TabSelect">
    <TabItem.Header>
        <TextBlock FontSize="12pt">error log</TextBlock>
    </TabItem.Header>
    <Grid><ListView Name="JfifoList" ItemsSource="{Binding JFifoErrorCollection}" Background="Transparent">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Time}" Header="time" Width="100" />
                    <GridViewColumn DisplayMemberBinding="{Binding FEStatus}" Header="fe status" Width="100" />
                    <GridViewColumn DisplayMemberBinding="{Binding BEStatus}" Header="be status" Width="100" />
                    <GridViewColumn DisplayMemberBinding="{Binding Trigger}" Header="trigger" Width="100" />
                </GridView>
            </ListView.View>
        </ListView></Grid>
</TabItem>

I do set up the list's DataContext as "this" window: 我确实将列表的DataContext设置为“ this”窗口:

JfifoList.DataContext = this;

When debugging I can see that the collection is populated, so there is data to display... Though also when debugging, I repeatedly see an error that says "A first chance exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll" in the debug output. 调试时,我可以看到集合已填充,因此有数据要显示。尽管也调试时,我反复看到一个错误,指出“ PresentationFramework.dll中发生了'System.NotSupportedException'类型的第一次机会异常”在调试输出中。

EDIT: I've looked around some more and found that UI elements must be updated in the UI thread... for some reason (I haven't created any in the code) there are numerous threads running in my program, and they all seem to be updating my ObservableCollection... Don't know whether this might be the problem... 编辑:我看了更多,发现UI元素必须在UI线程中更新...由于某种原因(我没有在代码中创建任何东西)程序中运行着很多线程,并且它们都似乎正在更新我的ObservableCollection ...不知道这可能是问题所在...

Modifications on the content of lists which are binded to a view, have to be done in a UI thread. 必须在UI线程中对绑定到视图的列表内容进行修改。 To catch your App UI thread, you can use something like this: 要捕获您的App UI线程,您可以使用如下代码:

Application.Current.Dispatcher.Invoke(DispatcherPriority.Render, new Action(() => JfifoList = whateverData));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM