Click here to Skip to main content
15,885,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted
Updated 7-Jun-12 6:19am
v5
Comments
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?

1 solution

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

1) remove the following:

XML
<border cornerradius="11" />


2) add the border element back into the following:

XML
<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>
 
Share this answer
 

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



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