Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0 Exception
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"
             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?
Posted 5-Jun-12 5:50am
Edited 7-Jun-12 7:19am
v5
Comments
db7uk at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 7-Jun-12 16:11pm
   
The binding is listed up above! Can you see where I screwed the pooch?
db7uk at 7-Jun-12 16:21pm
   
I think. In your listview, just take the border (corner radius thing) out. This does not look right.
db7uk at 7-Jun-12 16:24pm
   
If this works, I would suggest moving the border into the listview.view segment??
SASS_Shooter at 7-Jun-12 17:11pm
   
Looks like that was the issue!

1 solution

Rate this: bad
good
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:
 
<listview.borderbrush>
                <solidcolorbrush color="#99FFFFFF" opacity="0" />
            </listview.borderbrush>
            <listview.background>
                <solidcolorbrush color="#99FFFFFF" opacity="0" />
            </listview.background>
            <listview.view>
                <border cornerradius="11" />
                ....
            </listview.view>
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 230
2 DamithSL 200
3 Zoltán Zörgő 149
4 BillWoodruff 120
0 OriginalGriff 7,610
1 DamithSL 5,559
2 Sergey Alexandrovich Kryukov 5,324
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 7 Jun 2012
Copyright © CodeProject, 1999-2014
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