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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:19:00+00:00 2026-06-18T11:19:00+00:00

I have a ObservableCollection which I need to bind to 2 labels, first to

  • 0

I have a ObservableCollection which I need to bind to 2 labels, first to show count of items in the collection and second to show the sum of values.

First label is bound to collections count property and second label is bound directly to ObservableCollection with a convertor to calculate total of all items

XAML looks something like this

<Grid>
    <ListBox Name="itemList" ItemsSource="{Binding DataList}"/>
    <Label Name="lblcount" Content="{Binding DataList.Count}" />
    <Label Name="lblTotal" Content="{Binding DataList, Converter={StaticResource calculateTotalConvertor}" />
</Grid>

My VM has a collection like this

    ObservableCollection<int> data = new ObservableCollection<int>();

    public ObservableCollection<int> DataList
    {
        get { return data; }
        set { data = value; }
    }

My convertor code is

public class CalculateTotalConvertor : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        ObservableCollection<int> collection = value as ObservableCollection<int>;

        return collection.Sum();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Issue is on adding new items in DataList, ListView and label showing count of items gets updated but “lblTotal” doesnt get updated with total count.

Basically how to force your binding to be evaluated on ObservableCollection changes ? How does it work directly for ListView or DataGrid but not for label ?

I know this problem can be solved by creating a property in VM to show total and raise property change when collection gets updated but is there is any better solution than that ?

Of-course this is simplified form of my actual problem, I dont have access to the ViewModel and the collection, its a third party control. I am creating a wrapper user control and have a relative binding with the view to its inner collection.

  • 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-18T11:19:01+00:00Added an answer on June 18, 2026 at 11:19 am

    The other answers correctly explain why it is not updating. To force it to update you can change your converter to an IMultiValueConverter:

    public class CalculateTotalConvertor : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            ObservableCollection<int> collection = values.FirstOrDefault() as ObservableCollection<int>;
    
            return collection.Sum();
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    Then change your binding to a MultiBinding which also pulls in the Count:

    <Label Name="lblTotal">
        <Label.Content>
            <MultiBinding Converter="{StaticResource calculateTotalConvertor}">
                <Binding Path="DataList"/>
                <Binding Path="DataList.Count"/>
            </MultiBinding>
        </Label.Content>
    </Label>
    

    Now the second binding will notify that the binding needs to update when items are added or removed, but you can just ignore the count value and not use it.

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

Sidebar

Related Questions

I have ItemsControl which I bind to ObservableCollection On my view model I just
I have a combo box that I bind to an observable collection, which gets
I have an ObservableCollection<Data> Items Data has a Columns property on it which is
I would like to use a WrapPanel. I have a ObservableCollection with ViewModels which
I have a Silverlight delegate which gets an ObservableCollection in the EventArgs Result. The
I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
I have a collection private ObservableCollection<Contact> _contacts; In the constructor of my class I
In WPF app I have a ListView which is connected with ObservableCollection ShQuCollection through
I need to bind a Label to two ListBox es. In order to do
I have a ListBox which is bound to ObservableCollection of LogMessages. public ObservableCollection<LogMessage> LogMessages

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.