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

The Archive Base Latest Questions

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

I cannot get a two-way bind in WPF to work. I have a string

  • 0

I cannot get a two-way bind in WPF to work.

I have a string property in my app’s main window that is bound to a TextBox (I set the mode to ‘TwoWay’).

The only time that the value of the TextBox will update is when the window initializes.

When I type into the TextBox, the underlying string properties value does not change.

When the string property’s value is changed by an external source (an event on Click, for example, that just resets the TextBox’s value), the change doesn’t propagate up to the TextBox.

What are the steps that I must implement to get two-way binding to work properly in even this almost trivial example?

  • 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. 2026-05-10T20:52:16+00:00Added an answer on May 10, 2026 at 8:52 pm

    Most probably you’re trying to bind to a .net CLR property instead of a WPF dependencyProperty (which provides Change Notification in addition to some other things).
    For normal CLR property, you’d need to implement INotifyPropertyChanged and force update on the textbox in the event handler for PropertyChanged.

    • So make your object with the property implement this interface, raise the event in the property setter. (So now we have property change notification)
    • Make sure the object is set as the DataContext property of the UI element/control

    This threw me off too when I started learning about WPF data binding.

    Update: Well OP, it would have been a waste of time if i was barking up the wrong tree.. anyways now since you had to dig a bit.. you’ll remember it for a long time. Here’s the code snippet to round off this answer. Also found that updating the textbox happens automatically as soon as I tab-out.. You only need to manually subscribe to the event and update the UI if your datacontext object is not the one implementing INotifyPropertyChanged.

    MyWindow.xaml

    <Window x:Class='DataBinding.MyWindow' ...     Title='MyWindow' Height='300' Width='300'>     <StackPanel x:Name='TopLevelContainer'>         <TextBox x:Name='txtValue'  Background='AliceBlue' Text='{Binding Path=MyDotNetProperty}' />         <TextBlock TextWrapping='Wrap'>We're twin blue boxes bound to the same property.</TextBlock>         <TextBox x:Name='txtValue2'  Background='AliceBlue' Text='{Binding Path=MyDotNetProperty}' />     </StackPanel> </Window> 

    MyWindow.xaml.cs

    public partial class MyWindow : Window, INotifyPropertyChanged {     public MyWindow()     {         InitializeComponent();         this.MyDotNetProperty = 'Go ahead. Change my value.';         TopLevelContainer.DataContext = this;     }      private string m_sValue;     public string MyDotNetProperty     {         get { return m_sValue; }         set         {             m_sValue = value;             if (null != this.PropertyChanged)             {                 PropertyChanged(this, new PropertyChangedEventArgs('MyDotNetProperty'));             }         }     }      #region INotifyPropertyChanged Members     public event PropertyChangedEventHandler PropertyChanged;     #endregion } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 104k
  • Answers 104k
  • 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 I think what you want is this: http://www.corybennett.org/download/javascript-mode.el Then again,… May 11, 2026 at 8:31 pm
  • Editorial Team
    Editorial Team added an answer You want to create a formula field and add the… May 11, 2026 at 8:31 pm
  • Editorial Team
    Editorial Team added an answer Functions in JavaScript are passed by value. The alert() function… May 11, 2026 at 8:31 pm

Related Questions

In socket programming, you create a listening socket and then for each client that
I've seen a couple of questions over the last few days that have used
Is it possible to get two separate programs to communicate on the same computer
I have two collections which have property Email in both collections. I need to

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.