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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:04:54+00:00 2026-05-18T08:04:54+00:00

If one were to compile and run the following code, one would find that

  • 0

If one were to compile and run the following code, one would find that selecting and/or deselecting a row causes a line to be written to the Output window (as closer inspection of said code would lead one to believe).

After a short time of changing the selected row of the grid using the arrow keys (holding the Up and Down arrows respectively to traverse the entire data set a few times), one would be shocked (as I was) to notice that Output messages cease, even while continuing to cycle through the grid’s rows.

I am attempting to achieve something similar to what was given in this answer.

I am absolutely baffled. What would cause Bindings on my grid to spontaneously fail? Any and all help here would be MUCH appreciated!! Also, should anyone have the time to reproduce this, please comment with your findings.

XAML:

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <DataGrid Name="TheGrid">
            <DataGrid.Resources>
                <Style TargetType="{x:Type DataGridRow}">
                    <Setter Property="IsSelected" 
                            Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
                </Style>
            </DataGrid.Resources>
            <DataGrid.Columns>
                <DataGridTextColumn IsReadOnly="True" 
                                    Binding="{Binding Name}" Header="Name"/>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

Code-behind:

using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;

namespace WpfApplication1 {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            TheGrid.ItemsSource = Enumerable.Range(1, 100)
                                 .Select(i => new MyClass("Item " + i));
        }
    }

    public class MyClass : INotifyPropertyChanged {
        public string Name { get; private set; }

        private bool m_IsSelected;
        public bool IsSelected {
            get {
                return m_IsSelected;
            }
            set {
                if (m_IsSelected != value) {
                    m_IsSelected = value;
                    Console.WriteLine(Name + ": " + m_IsSelected);
                    PropertyChanged(this, 
                        new PropertyChangedEventArgs("IsSelected"));
                }
            }
        }

        public MyClass(string name) {
            Name = name;
        }

        public event PropertyChangedEventHandler PropertyChanged = 
                                                            delegate { };
    }
}

Thanks in advance!

EDIT:

  • Tried applying the DataGridRow
    Style using the RowStyleSelector
    property – fail.

  • Tried applying the DataGridRow Style using the Row_Loading and Row_Unloading events – fail.

  • Tried using a custom MultiSelectCollectionView – fail (didn’t work with DataGrid control)

  • Tried setting VirtualizingStackPanel.IsVirtualizing="False"– fail (unusably slow with hundreds of rows)

  • Tried messing with VirtualizingStackPanel.VirtualizationMode (Standard or Recycled) – fail.

As stated in one of my comments below, the overarching problem is that I need to bind the SelectedItems property of the DataGrid to my ViewModel, but can’t, since SelectedItems is read-only.

There HAS to be some kind of pure-MVVM, out-of-the-box solution for this, but so far, it eludes me!

  • 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-18T08:04:54+00:00Added an answer on May 18, 2026 at 8:04 am

    I just tried this and had the same behavior. I was able to fix the problem by changing the DataGrid to prevent it from virtualizing as follows: <DataGrid Name="TheGrid" AutoGenerateColumns="False" VirtualizingStackPanel.IsVirtualizing="False">.

    For more information see this MSDN forum post.

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

Sidebar

Related Questions

No related questions found

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.