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

Related Questions

I have a class that implements the INotifyPropertyChanged interface. If I create a new
I have the following data model class defined: @PersistenceCapable public class TestSerializableModelObj { @Persistent(serialized=true,
I'd like to have an object that implements both the Map and the List
I am quite new to WPF and I am confused about how Data Bindings
I personally don't have my entities implement interfaces. For a Task class I wouldn't
I have Googled and read for hours now and I can't find anyone that
I have an Excel plug-in (written in C#) with a static variable that is
I'm using the Point Class to manage a list of (x,y) coordinates and I
Perhaps I don't understand events fully. I'm building a Windows Phone 7 app in
Is there any way to deserialize in PHP an object serialized in Java? IE

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.