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

  • Home
  • SEARCH
  • 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 1092407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:40:39+00:00 2026-05-16T23:40:39+00:00

Scenario: A ListView is DataBound to an ObservableCollection<CustomClass> and is displaying it’s items through

  • 0

Scenario: A ListView is DataBound to an ObservableCollection<CustomClass> and is displaying it’s items through a custom ItemTemplate. The CustomClass just contains three string properties and one boolean property and already has INotifyPropertyChanged implemented on every of it’s four properties. The custom ItemTemplate of the ListView has One-Way bindings on the three string properties and a Two-Way binding on the boolean property, displaying it as a CheckBox.

Problem: I’m looking for the most elegant (in terms of WPF) way to display the count of all checked items in that ListView using a TextBlock – or in other words, all items that have their boolean property set to true in that collection. I want that TextBlock to immediately update the displayed count if one of the ListView items gets checked/unchecked. I know that there are (rather) ugly ways to achieve this with code behind and eventhandling, but I’d like to know if there’s a clever way to do this maybe completely in XAML with arcane DataBinding syntax.

Edit: Just as an example/clarification: The ListView displays 100 items, 90 items have their boolean property set to true, so the TextBlock will display ’90’. If the user unchecks one more item through it’s CheckBox and therefore sets it’s property to false through the Two-Way binding, the TextBlock should update to ’89’.

  • 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-16T23:40:40+00:00Added an answer on May 16, 2026 at 11:40 pm

    Thanks for all the answers I’ve got, these were all applicable solutions but unfortunately not really what I’ve tried to achieve. So this is how I’ve solved the problem now:

    I’ve implemented a DependencyProperty on the Window containing the TextBlock:

    public static readonly DependencyProperty ActiveItemCountProperty =
            DependencyProperty.Register("ActiveItemCount", typeof(int), typeof(CustomControl), new UIPropertyMetadata(0));
    

    On the DataTemplate for the ListView items the CheckBox registered an EventHandler for the Click-Event:

    <CheckBox IsChecked="{Binding Active, Mode=TwoWay}" Click="CheckBox_Click" />
    

    The event handler in code behind looks something like this:

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<CustomClass> sourceCol = listView.DataContext as ObservableCollection<CustomClass>;
            if (sourceCol != null)
                ActiveItemCount = sourceCol.Count(x => x.Active);
        }
    

    And obviously, the TextBlock is just data bound to this DependencyProperty:

    <TextBlock Text="{Binding Path=ActiveItemCount, ElementName=ControlRoot}" />
    

    With ControlRoot being the name of the Window.

    • 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.