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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:42:24+00:00 2026-05-13T19:42:24+00:00

I have a data class that implements INotifyPropertyChanged and two WPF controls that DataBind

  • 0

I have a data class that implements INotifyPropertyChanged and two WPF controls that DataBind to the same value. Only one WPF control is updated, why?

Here is my data class:

using System;
using System.ComponentModel;
using System.Windows.Threading;

namespace TestMultiBind
{
    class DataSource : INotifyPropertyChanged
    {
        static int _DataValue;
        static DispatcherTimer tmr = new DispatcherTimer();
        static int _ClientCount = 0;

        #region InotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        public int DataValue
        {
            get { return _DataValue; }
        }

        public DataSource()
        {
            if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                _ClientCount = _ClientCount + 1;
                if (!tmr.IsEnabled)
                {
                    tmr.Interval = TimeSpan.FromMilliseconds(10);
                    tmr.Tick += new EventHandler(tmr_Tick);
                    tmr.Start();
                }
            }
        }
        void tmr_Tick(object sender, EventArgs e)
        {
            _DataValue = DateTime.Now.Second;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("DataValue"));
            }
        }
    }

}

and here is my XAML

Title="Window1" Height="300" Width="300">
<Grid>
    <StackPanel>
        <ProgressBar Height="20"  Name="progressBar1" Value="{Binding Mode=OneWay, Path=DataValue}" Maximum="60">
            <ProgressBar.DataContext>
                <ds:DataSource/>
            </ProgressBar.DataContext>
        </ProgressBar>
        <ProgressBar Height="30"  Name="progressBar2" Value="{Binding Mode=OneWay, Path=DataValue}" Maximum="60">
            <ProgressBar.DataContext>
                <ds:DataSource/>
            </ProgressBar.DataContext>
        </ProgressBar>
    </StackPanel>
</Grid>

I have tried to present the simplest example possible, thus I created a data class that uses a timer to update a value once per second. The real world problem I am trying to solve is data coming across a serial port that is to be displayed. Thus I need to store static data for the incoming data within the class as well as handling instance specific events for each of the clients (WPF controls) that are data bound to the control.

It would appear that my tmr_Tick routine is somehow instance specific to the first client as opposed to being static to the class and raising the multiple events required for each of the clients.

What am I missing here or doing wrong?

  • 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-13T19:42:24+00:00Added an answer on May 13, 2026 at 7:42 pm

    I’m not sure if this is the best way to do this, but it works. The problem with my initial code was that I needed both a static and a instance constructor for the class. The timer is created in the static constructor (which is only run once) while there needs to be one event handler per binding so this is handled in the instance constructor.

    Here is the code that works:

    using System;
    using System.ComponentModel;
    using System.Windows.Threading;
    
    namespace TestMultiBind
    {
        class DataSource : INotifyPropertyChanged
        {
            static int _DataValue;
            static DispatcherTimer tmr = new DispatcherTimer();
    
            #region InotifyPropertyChanged Members
            public event PropertyChangedEventHandler PropertyChanged;
            #endregion
    
            public int DataValue
            {
                get { return _DataValue; }
            }
    
            static DataSource()
            {
                if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
                {
                    tmr.Interval = TimeSpan.FromMilliseconds(10);
                    tmr.Start();
                }
            }
            public DataSource()
            {
                if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
                {
                    tmr.Tick += new EventHandler(tmr_Tick);
                }
            }
            void tmr_Tick(object sender, EventArgs e)
            {
                _DataValue = DateTime.Now.Second;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("DataValue"));
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 337k
  • Answers 337k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It does seem like something like this should exist, but… May 14, 2026 at 4:08 am
  • Editorial Team
    Editorial Team added an answer COM objects are referenced via Interfaces, which you don't need… May 14, 2026 at 4:08 am
  • Editorial Team
    Editorial Team added an answer Laserallan's approach is the way to go. For a vector… May 14, 2026 at 4:08 am

Related Questions

I have a custom object that implements INotifyPropertyChanged. I have a collection of these
First off, there's a bit of background to this issue available on my blog:
Say you have a customer object and the customer file form that manipulates that
A little background: I am loading a WPF UI from a database which is
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.