Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:23:03+00:00 2026-06-05T10:23:03+00:00

I have a listview for which I want to format several fields from a

  • 0

I have a listview for which I want to format several fields from a populating object. Initially I created a data template which threw an InvalidOperationException with a blank page and no indication of the cause of the exception. I found an article on CodeProject and I have the datatemplate now embedded in a Setter definition:

<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 
                            Background="Transparent"
                            Foreground="Black" 
                            FontSize="12" 
                            Text="{Binding Path=CurrentEvent.EventTypeName, Mode=OneWay}" />
                        <TextBlock 
                            Background="Transparent"
                            Foreground="Black" 
                            FontSize="12" 
                            Text="{Binding Path=CurrentEvent.EventMessage, Mode=OneWay}" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock 
                                Background="Transparent" 
                                Foreground="Black" 
                                FontSize="8" 
                                Text="{Binding Path=CurrentEvent.EventLoggedOn, Mode=OneWay}"
                                Margin="0,0,10,0" />
                            <TextBlock
                                Background="Transparent" 
                                Foreground="Black" 
                                FontSize="8"
                                Text="{Binding Path=CurrentEvent.Program, Mode=OneWay}" />
                            <TextBlock 
                                Background="Transparent" 
                                Foreground="Black" 
                                FontSize="8"
                                Text=":" />
                            <TextBlock 
                                Background="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>

With the definition ASIS I now get a runtime exception and it is finally pointing at the XAML. But I still do not understand why I’m getting it. The exception:

‘Add value to collection of type ‘System.Windows.Controls.ItemCollection’ threw an exception.’ Line number ’55’ and line position ’13’.

It has the inner exception:

{“Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.”}

I’m clearly using ItemsSource so why am I getting this exception??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:23:05+00:00Added an answer on June 5, 2026 at 10:23 am

    It turned out that the setting of the border and background brushes in the main line of the XAML was the issue. I removed them and use Setter.Property in my DataTemplate and the application runs now.

    So for future designs: when defining the look of a ListView with a data template, it is important that styling remain with the data template. My final page design ended up to be significantly different as I added some formatting following this blog

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following problem. I have a ListView which returns data from SQL
I have a ListView in which data is streaming (changing). I want to just
I have a ListView in which i want to create an event when the
I have ListView which is saving all data to database. For adding i have
I have a ListView which I've created a custom view for each row. My
I have created a ListView which contains a list of items. Each item in
Introduction I have a ListView and want to format only the second column. The
I have a list of objects which i want to bind to a ListView
I have a listview which has a bunch of selections. I want to keep
i have a ListView which contains objects bound from an collection. The representation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.