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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:04:30+00:00 2026-05-30T19:04:30+00:00

I have a WPF Data Grid bound to an observable collection, which is working

  • 0

I have a WPF Data Grid bound to an observable collection, which is working as intended.

What I am trying to do now is add text below it to say: “Number of selected rows: {count goes here}“

What’s the proper way to do this? I could add a new property in the View Model called SelectedCount or something similar and bind to that, but it doesn’t feel right. It seems redundant. Also, I could set the label text dynamically in the code behind, but I’m not sure if that’s the “right” place to do this either.

Here’s an example below.

EDIT:

Please pretend there’s a checkbox column header whose intention is to provide check/uncheck all functionality. The state of this header checkbox should not count towards the final count.

example

  • 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-30T19:04:31+00:00Added an answer on May 30, 2026 at 7:04 pm

    You could use element binding to declaratively bind to the SelectedItems.Count property in XAML:

    <TextBlock Text="{Binding ElementName=MyDataGrid,
       Path=SelectedItems.Count, StringFormat=Number of selected rows: {0}}" />
    

    Update

    Presumably you’re using MVVM, so adding a SelectedXCount property to your view model is a perfectly reasonable application of the view model. The advantage of having it in the view model is that you could unit test based on the number of selected items. E.g. if you want to check that the user can only progress (a CanNext property returns true) if the user has selected some items.

    The SelectedItems property is not a DependencyProperty so can’t be bound to, but there are many articles online that get around the issue when using the DataGrid in MVVM. Most of the solutions involve using a mechanism for calling a view model command on the invocation of the DataGrid’s SelectionChanged event.

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

Sidebar

Related Questions

I have a wpf datagrid which is bound to an observable collection. Currently I
Is it possible to have a pure hierarchical wpf data grid? Now there are
We have a data grid on a window that is bound to a collection
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have a WPF ListBox bound to a data object. Inside the listbox are
I have a WPF DataGrid bound to ObservableCollection . Each item in my collection
I have a DataGrid in my WPF window which is bound to a database.
I have a DataGrid in WPF. And I am trying to add Button s
In my WPF app I have a data import function which imports data from
using WPF/C#/Entity Framework. I have a DataGrid.ItemsSource bound to some ObservableCollection . Now, I

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.