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 7693957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:12:31+00:00 2026-05-31T21:12:31+00:00

I need to deal with a large amount of data in a WPF application.

  • 0

I need to deal with a large amount of data in a WPF application.

I have bound the large collection to a ListView and I’m using the ItemContainerStyle to bind the list item’s IsSelected property with my object’s IsSelected property, so that when the item is selected in the ListView, my objects’ IsSelected property will also be set to true. By doing this I can easily cary out commands on only the objects that have been selected in the list.

I use UI virtualization in the ListView because the app would be sluggish otherwise. But because only a subset of my whole collection is visible in the list, when I use CTRL+A to select all the items in my list, only the items that are loaded have their IsSelected property set to true. The items that are not visible (the items that are virtualized) have their IsSelected property set to false. This is a problem because when I select all the items in the list, I expect that the IsSelected property is set to true for all the items in the collection.

I have created some sample code to illustrate the problem:

MainWindow.xaml

<Window x:Class="VirtualizationHelp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" x:Name="wnd">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Button Grid.Row="0" Content="Click me" Click="Button_Click" />
    <ListView Grid.Row="1" ItemsSource="{Binding Path=Persons, ElementName=wnd}">
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
            </Style>
        </ListView.ItemContainerStyle>
    </ListView>
</Grid>
</Window>

MainWindow.xaml.cs

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace VirtualizationHelp
{
    public partial class MainWindow : Window
    {
        List<SelectablePerson> _persons = new List<SelectablePerson>(10000);
        public List<SelectablePerson> Persons { get { return _persons; } }
        public MainWindow()
        {
            for (int i = 0; i < 10000; i++)
            {
                SelectablePerson p = new SelectablePerson() { Name = "Person " + i, IsSelected = false };
                _persons.Add(p);
            }
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int count = Persons.Where(p => p.IsSelected == true).Count();
            (sender as Button).Content = count.ToString();
        }
    }

    public class SelectablePerson
    {
        public string Name { get; set; }
        public bool IsSelected { get; set; }
        public override string ToString()
        {
            return Name;
        }
    }
}

When the button on top of the form is clicked, it counts the items in the collection that have the “IsSelected” property set to true. You can see that when you press CTRL+A to select all items in the list, it shows that only 19 items are selected.

Does anybody know a way around this problem? I can’t turn virtualization off because I would get horrible performance.

  • 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-05-31T21:12:32+00:00Added an answer on May 31, 2026 at 9:12 pm

    I think it’s your binding. Basically you’re updating/binding the ListViewItem, which will update only the visible ones, not the whole list. I’ll play with it, for now you can parse in code bind..

    <Window x:Class="VirtualizationHelp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" x:Name="wnd">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <TextBlock x:Name="txtSelectedItemsCount"/>
            <ListView Grid.Row="1" ItemsSource="{Binding Path=Persons, ElementName=wnd}" 
             SelectionChanged="ListView_SelectionChanged"/>
        </Grid>
    </Window>
    
    private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var lv = (ListView) sender;
        txtSelectedItemsCount.Text = lv.SelectedItems.Count.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a large amount of data and need to do
My application has to deal with large amounts of data, usual select size is
I have quite large files that I need to deal with (500Meg+ zip files).
We have a very large Java Swing desktop application comprising of a great deal
I have a ListView that contains a large collection of rows with textboxes that
I have to deal with an API which need to be provided a DataSource
I have several array to deal with. I need to extract the most duplicate
As a C++ programmer I sometimes need deal with memory buffers using techniques from
I am trying to deal with a very large dataset. I have k =
I have to deal with what is pretty ugly and large blob of ColdFusion

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.