Click here to Skip to main content
12,765,241 members (37,599 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF C#4.0 Exceptions
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.
<UserControl x:Class="Servpro.Framework.ViewerModule.Views.MenuView"
             d:DesignHeight="580" d:DesignWidth="210">
        <Style TargetType="ListView">
            <Setter Property="ItemTemplate">
                        <StackPanel Orientation="Vertical">
                                Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" />
                                Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" />
                            <StackPanel Orientation="Horizontal">
                                    Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
                                    Margin="0,0,10,0" />
                                    Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" />
                                    Text=":" />
                                    Text="{Binding Path=CurrentEvent.Method, Mode=OneWay}" />
    <Grid Margin="4">
            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" />
                <SolidColorBrush Color="#99FFFFFF" Opacity="0"/>

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?
Posted 5-Jun-12 5:50am
Updated 7-Jun-12 7:19am
db7uk 6-Jun-12 17:58pm
Hi, I re-created your control and created a dummy viewmodel to bind to. Unfortunatly I am not getting any exception. The combo box is populated as expected and the button (nice by the way) is fine. Do you have a template applied to the combo box that I am not seeing? I obtained more information on the xaml markup from the post at Stackoverflow.
SASS_Shooter 6-Jun-12 18:00pm
No I have no formatting or template for the combobox. that was next. I'm befuddled by this. I don't even remember changing this before it started breaking. Now I cannot stop it from breaking. :( This version is my stripped down control where I'm trying to eliminate all possible sources of malformed XAML.
db7uk 6-Jun-12 18:08pm
It is strange. I have it working on my test application. Does the usercontrol sit somewhere it should not on its parent? And to confirm that the EventTypeList is empty? (Does not matter really though as I have used a filled or empty collection to bind to. It works either way.)
SASS_Shooter 6-Jun-12 18:16pm
I'm using Prism and it is bound to the correct region. It was even working without issues!!! I did some work on another control trying to format items on the ListView in another region and ran my app to see how it looked when I did my search. That is when the errors began. I've backed out tons of xaml to try and fix it and yet even in it's simple state as shown I get the exception. Driving me NUTS!!!!! It should not happen.
db7uk 7-Jun-12 4:11am
Agree, this must be a right pain in the rear. Out of pure morbid curiosity, does the app run ok with out the search control injected into the region?
SASS_Shooter 7-Jun-12 10:36am
Well first I tried the "fix Microsoft" approach.....deleted the form and recreated it. No good. And in answer to your question, I have to remove all bound forms leaving just the Title view in order to get the application running. Grrrr. But I did find some binding issues in the output window so now I'm working on eliminating all binding errors and see what happens. I am also thinking of eliminating ViewModel injection and just do the binding in XAML.

Secondary note: Ahhh added the search menu back in and guess what....that works! So it is one of the other forms that is giving me a pain in the arse.
SASS_Shooter 7-Jun-12 10:48am
Found the offender and it is with a custom ListView design. But still cannot figure out why my template is causing issues.
db7uk 7-Jun-12 16:10pm
Glad you are making some grounds. If you need another pair of eyes I am more than happy to help although I have not been able to fix the issue ?!?!?!
SASS_Shooter 7-Jun-12 16:11pm
The binding is listed up above! Can you see where I screwed the pooch?
db7uk 7-Jun-12 16:21pm
I think. In your listview, just take the border (corner radius thing) out. This does not look right.
db7uk 7-Jun-12 16:24pm
If this works, I would suggest moving the border into the listview.view segment??
SASS_Shooter 7-Jun-12 17:11pm
Looks like that was the issue!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ok, based on our recent conversations I hope this was the solution.

1) remove the following:

<border cornerradius="11" />

2) add the border element back into the following:

                <solidcolorbrush color="#99FFFFFF" opacity="0" />
                <solidcolorbrush color="#99FFFFFF" opacity="0" />
                <border cornerradius="11" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 7 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100