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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:56:35+00:00 2026-05-15T09:56:35+00:00

I am (very) new to WPF and I have got a question regarding that.

  • 0

I am (very) new to WPF and I have got a question regarding that. It may be a very stupid one, so please excuse me if that is the case.

I am doing a project where I am binding my textboxes, etc to static properties inside a singleton class. My problem is that the twoWay Binding is not working. When the textbox changes, I can see that the value of the property changes, but when the property changes, I can’t see the textbox text changing.

To see what’s going on I wrote a small app, with just the relevant code. Please find the code below.

In the code below, I am changing the text in the textbox and source property in various places and noted my observations. If someone can tell me what I am doing wrong and point me in the right direction, I would be very grateful.

I also tried INotifyPropertyChanged, but it gives problems because of the static property. Is there a different approach when implementing INotifyPropertyChanged for a static property.

Thanks in advance,
Abhi.

XAML:

<Page x:Class="TestBindingApp.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Prefs="clr-namespace:TestBindingApp"
  xmlns:cm="clr-namespace:System.ComponentModel;assembly=System"
  xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
  xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
Title="Page1" Loaded="Page_Loaded">
<Page.Resources>
    <Prefs:Class1 x:Key="TClass"></Prefs:Class1>
</Page.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal" Margin="15 5 5 0" Height="20">
        <TextBlock Name="txbBankNumber" Margin="50 0 0 0" Padding="2">Bank Account Number :</TextBlock>
        <TextBox Name="txtBankNumber" Margin="10 0 0 0" Width="100" MaxLength="8" HorizontalAlignment="Left">
            <TextBox.Text>
                <Binding Source="{StaticResource TClass}" Path="AccountNumber" Mode="TwoWay" NotifyOnValidationError="True" UpdateSourceTrigger="PropertyChanged">
                </Binding>
            </TextBox.Text>
        </TextBox>
    </StackPanel>

</Grid>

XAML.CS:

namespace TestBindingApp
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
    public Page1()
    {

        InitializeComponent();

        txtBankNumber.Text = "ABC";
 // I can see the property AccountNumber changing here
        Class1.AccountNumber = "123456";
 // Value in txtBankNumber doesn't change here
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        txtBankNumber.Text = "ABCDE";
 // I can see the property AccountNumber changing here

        Class1.AccountNumber = "12345678";
 // Value in txtBankNumber doesn't change here

    }
}

}

Class Class1:

using System.ComponentModel;

namespace TestBindingApp
{
public class Class1
{
    // Singleton instance
    private static Class1 instance;
    private static string _accountNumber;
    public Class1()
    {

    }

    // Singleton instance read-only property
    public static Class1 Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Class1();
            }
            return instance;
        }
    }

    public static string AccountNumber
    {
        get
        {
            return _accountNumber;
        }
        set
        {
            if (value != _accountNumber)
            {
                _accountNumber = value;
            }
        }
    }
}

}

=====================

Couldn’t post my updated code in the comments, so updating my original post.

Below is my updated code, which has the “if(PropertyChanged != null)”, but it gives me an error – “An object reference is required for the non-static field, method, or property ‘TestBindingApp.Class1.NotifyPropertyChanged(string)'”. .

I have just started learning WPF, so if you could explain in detail, that would be very helpful. Thanks for your patience.

using System.ComponentModel;

namespace TestBindingApp
{
public class Class1: INotifyPropertyChanged
{
    // Singleton instance
    private static Class1 instance;
    private static string _accountNumber;
    public event PropertyChangedEventHandler PropertyChanged;

    public Class1()
    {

    }

    // Singleton instance read-only property
    public static Class1 Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Class1();
            }
            return instance;
        }
    }

    public static string AccountNumber
    {
        get
        {
            return _accountNumber;
        }
        set
        {
            if (value != _accountNumber)
            {
                _accountNumber = value;
                NotifyPropertyChanged("AccountNumber");
            }
        }
    }

    private void NotifyPropertyChanged(string property)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(property));
    } 

}

}

==============

Updated 23rd June, 09:53 AM UK time

Hi Arcturus, I have changed the properties to non-static, but it is still not behaving as I expect it to. Am I expecting it to do something which it isn’t meant to do, or am I doing something wrong.
In the below code, I expected the textbox to show 12345678 (or maybe 123456) as the account number, but it still shows 123. In the debug mode, I can see PropertyChanged event executing correctly after each property change statement, but the value of the textbox doesn’t change. Does the binding take affect only at the time of initialization (InitializeComponent()), or am I missing something here?

Page code-behind

namespace TestBindingApp
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
    public Page1()
    {
        Class1.Instance.AccountNumber = "123";
        InitializeComponent();
        Class1.Instance.AccountNumber = "123456";
    }

    private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Class1.Instance.AccountNumber = "12345678";
    }
}
}

Class1.cs

namespace TestBindingApp
{
public class Class1: INotifyPropertyChanged
{
    // Singleton instance
    private static Class1 instance;
    private static string _accountNumber;
    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    public Class1()
    {

    }

    // Singleton instance read-only property
    public static Class1 Instance
    {
        get
        {
            if (instance == null)
            {
                instance = new Class1();
            }
            return instance;
        }
    }

    public string AccountNumber
    {
        get
        {
            return _accountNumber;
        }
        set
        {
            if (value != _accountNumber)
            {
                _accountNumber = value;
                OnPropertyChanged("AccountNumber");
            }
        }
    }

    private void OnPropertyChanged(string property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    } 

}
}
  • 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-15T09:56:36+00:00Added an answer on May 15, 2026 at 9:56 am

    You really need the INotifyPropertyChanged interface:

    using System.ComponentModel;
    
    namespace TestBindingApp
    {
    public class Class1
    {
        // Singleton instance
        private static Class1 instance;
        private string _accountNumber;
        public Class1()
        {
    
        }
    
        // Singleton instance read-only property
        public static Class1 Instance
        {
        get
        {
            if (instance == null)
            {
            instance = new Class1();
            }
            return instance;
        }
        }
    
        public string AccountNumber
        {
        get
        {
            return _accountNumber;
        }
        set
        {
            if (value != _accountNumber)
            {
            _accountNumber = value;
                NotifyPropertyChanged("AccountNumber");
            }
        }
        }
    
            public event PropertyChangedEventHandler PropertyChanged;
    
    
        private void NotifyPropertyChanged(string property)
        {
            if(PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to WPF, so please bear with me. Basically I have defined
I have a WPF sorting/binding issue. (Disclaimer: I am very new to WPF and
I'm very new to WPF: I need to have buttons on a grid resize
I'm very new to .Net and WPF and have a problem. The code is
Let me start off by saying that I am very new to WPF and
I am very new and very inexperienced. I have downloaded a WPF version of
I am very new in WPF. I have been trying to do the following:
I got this code from a WPF (very simple) application that illustrate my problem
Couldn't find an answer to this one. I have a WPF ListView control that
I am very new in WPF. I have created a form style in Wpf

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.