Click here to Skip to main content
15,896,063 members

ListView issue getting exception on startup

SASS_Shooter asked:

Open original thread
After a great deal of debugging with NO INFORMATION PROVIDED BY MICROSOFT in the exception details, I finally received a great idea from a fellow code projecter. I pulled out all forms from the view until it loaded then began slowly putting them back. I now have isolated the offending code. It sure would save time if the exception could point me to the form that was processed at the time of this exception!
So here is the view that is barfing..changed how the template is applied following an article here on CodeProject.
HTML
<UserControl x:Class="Servpro.Framework.ViewerModule.Views.MenuView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="580" d:DesignWidth="210">
    <UserControl.Resources>
        <Style TargetType="ListView">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical">
                            <TextBlock 
                                removed="Transparent"
                                Foreground="Black" 
                                FontSize="12" 
                                Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" />
                            <TextBlock 
                                removed="Transparent"
                                Foreground="Black" 
                                FontSize="12" 
                                Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" />
                            <StackPanel Orientation="Horizontal">
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8" 
                                    Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
                                    Margin="0,0,10,0" />
                                <TextBlock
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8"
                                    Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" />
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8"
                                    Text=":" />
                                <TextBlock 
                                    removed="Transparent" 
                                    Foreground="Black" 
                                    FontSize="8" 
                                    Text="{Binding Path=CurrentEvent.Method, Mode=OneWay}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid Margin="4">
        <ListView 
            ItemsSource="{Binding Path=EventList, Mode=OneWay}" 
            Height="568" VerticalAlignment="Top" 
            Width="201" HorizontalAlignment="Left" 
            Margin="4" >
            <Border CornerRadius="11" />
            <ListView.BorderBrush >
                <SolidColorBrush Color="#99FFFFFF" Opacity="0" />
            </ListView.BorderBrush>
            <ListView.Background>
                <SolidColorBrush Color="#99FFFFFF" Opacity="0"/>
            </ListView.Background>
        </ListView>
    </Grid>
</UserControl>


The code behind hasn't changed from before .. injection of a view model and a public property to set the model in the DataContext. I found I had to change my order for setting DataContext. Now I get an exception
Add value to collection of type ItemCollection thre an exception. Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource. But I'm not putting anything in ItemCollection!

Ideas on how this is happening?
Tags: C# (C# 4.0), WPF, Exceptions

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900