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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:40:46+00:00 2026-05-23T07:40:46+00:00

I have a class named Data with some public members: Name , Age ,

  • 0

I have a class named Data with some public members: Name, Age, Address.

I have also window with text boxes Name, Age, Address.

The Data object can change any time.

How can I bind the Data object to the text boxes and follow after object changes?

I know there is INotifyPropertyChanged and “dependency-properties” but I do not know how to use them.

Edit

public class MyData : INotifyPropertyChanged
{
  private string _name;

  public string Name
  {
    get
    {
      return _name;
    }
    set
    {
      if (_name != value)
      {
        _name = value;
        OnPropertyChnged("Name");
      }
    }
   }
   public event PropertyChangedEventHandler PropertyChanged;

   protected void OnPropertyChanged(string name)
   {
     ProppertyChangedEventHandler handler = PropertyChanged;
     if (handler != null) handler(this, new PropertyChangedEventArgs(name));
   }
}

XAML code:

xmlns:myApp="clr-namespace:MyApp"
<Window.Resources><myApp:MyData x:key = data/></WindowResources>
<TextBox><TextBox.Text><Binding Source="{StaticResource data}" Path="Name" UpdateSourceTrigger="PropertyChanged"/></TextBox.Text></TextBox>

class OtherClass
{
  private MyData data;
  //the window that have the binding textbox
  private MyWindow window;
  public OtherClass()
  {
    data = new MyData();
    data.Name = "new name"
    window = new MyWindow();
    window.show();
  }
}
  • 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-23T07:40:46+00:00Added an answer on May 23, 2026 at 7:40 am

    This link from MSDN explains it well.

    MSDN link is dead, adding link to a similar article.

    When your class property is changed, your property should raise a OnPropertyChanged event with the name of the property so that the View knows to refresh it’s binding.

        public String Name
        {
            get { return _name; }
            set 
            {
                if (_name != value)
                {
                    _name = value;
                    this.OnPropertyChanged("Name");
                }
            }
        }
    

    And your textbox should have a binding such as:

    <TextBox Text="{Binding Name}"/>
    

    I have a ViewModelBase class which is where I have implemented my OnPropertyChandedEvent for all derived models to call:

        /// <summary>
        /// An event for when a property has changed.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    
        /// <summary>
        /// Virtual method to call the Property Changed method
        /// </summary>
        /// <param name="propertyName">The name of the property which has changed.</param>
        protected virtual void OnPropertyChanged(String propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named project with the following data members. class Project {
Suppose I have a class named Data . Another class annotates one of its
Say I have a class named Frog, it looks like: public class Frog {
I have following class as the main window: public partial class Window1 : Window
I have a class named OrganizerNote with fields: public long id; public DateTime CreationDate;
I have a class that contains some data, and I would like to add
i have class named Group i tried to test configuration: var cfg = new
I have a class named Page with a private property currently called _pageData which
I have a class named baseClass. From this class I inherit a class names
I have a Class named Constants that contains all the constant variable in my

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.