开发者

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 t开发者_如何学Gohere 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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜