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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:01:15+00:00 2026-05-14T20:01:15+00:00

I want to create a program which calculates how long it will take to

  • 0

I want to create a program which calculates how long it will take to repeat a process a certain number of times. I’ve scaled this down a lot for this example.

So, I have some textboxes which are bound to properties in a class:

Count: <TextBox x:Name="txtCount" Text="{Binding Count, Mode=TwoWay}" Width="50"/>
Days: <TextBox x:Name="txtDays" Text="{Binding Days, Mode=TwoWay}" Width="50"/>

and a textblock which is multibound like so:

<TextBlock x:Name="tbkTotal">
    <TextBlock.Text>
        <MultiBinding StringFormat="Days: {0}, Count: {1}">
            <Binding Path="Days" /> /* This isn't updating */
            <Binding Path="Count" />
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

My DataContext is set in the Window1.xaml.cs file.

public Window1()
        {
            InitializeComponent();
            Sample sample = new Sample();
            this.DataContext = sample;
        }

I can update the multibound textblock with the Count property just fine, but the Days property always shows 0, even though the Days input accurately reflects changes. I believe that this is because my accessors are different for Days – namely, the Set method. This class is in a different file.

public class Sample : INotifyPropertyChanged
    {
        private int _count;
        private TimeSpan _span;

        public int Count 
        { 
            get { return _count; } 
            set 
            { 
                _count = value;
                NotifyPropertyChanged("Count"); /* Doesn't seem to be needed, actually */
            } 
        }

        public TimeSpan Span { get { return _span; } }

/* The idea is to provide a property for Days, Hours, Minutes, etc. as conveniences to the inputter */

        public double Days
        {
            get { return _span.Days; }
            set
            {
                TimeSpan ts = new TimeSpan();
                double val = value > 0 ? value : 0;
                ts = TimeSpan.FromDays(val);
                _span.Add(ts); /* !! This turned out to be the problem, lol - see SixLetterVariables' answer below. */
                NotifyPropertyChanged("Span"); /* Here I can only get it to work if I notify that Span has changed - doesn't seem to be aware that the value behind Days has changed. */
            }
        }

        private void NotifyPropertyChanged(string property)
        {
            if (null != this.PropertyChanged)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
        public Sample()
        {
            _count = 0;
            _span = new TimeSpan();
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
  • 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-14T20:01:15+00:00Added an answer on May 14, 2026 at 8:01 pm

    Firstly TimeSpan is an immutable struct, so you’ll need to store the result of any operations otherwise it effectively is a no-op. Also, you’ll need to call OnPropertyChanged for both Span and Days being changed:

    public double Days
    {
        get { return _span.Days; }
        set
        {
            double val = value > 0 ? value : 0;
    
            // TimeSpan is an immutable struct, must store the result of any
            // operations on it
            _span = TimeSpan.FromDays(val);
    
            this.OnPropertyChanged("Days");
            this.OnPropertyChanged("Span");
        }
    }
    
    // This is preferred way for handling property changes
    private event PropertyChangedEventHandler propertyChanged;
    public event PropertyChangedEventHandler PropertyChanged
    {
        add { this.propertyChanged += value; }
        remove { this.propertyChanged -= value; }
    }
    
    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = this.propertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.