简体   繁体   中英

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. 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.

Here is the 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:

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.

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...

Modifications on the content of lists which are binded to a view, have to be done in a UI thread. To catch your App UI thread, you can use something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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