title: What triggers the binding on the UI?
body: <p>I have a TextBox in a WPF Window that I populate from the code behind (with a file name after the user has selected one from an OpenFileDialog.</p>
  
  <p>Although my TextBox.Text is bound to a String property in my ViewModel class, the property is not populated when the text is set into TextBox.Text.</p>
  
  <p>If I type into the TextBox, then the property is populated, so there must be some event firing or something that happens during user input and not when I set the value via the code.</p>
  
  <p>What is the the step I'm missing to properly bind?</p>
  
  <p>Also, is the set method on the property meant to be called when the property is changed, or the UI?  Or both?  If changing the UI calls the set method, which fires the PropertyChanged event to update the UI, what stops this looping forever?</p>
  
  <p><em>(I know I could set the property directly, but I feel I'm lacking understanding on binding and I'm hoping this will help fill some gaps.)</em></p>
  
  <p>My sample code:</p>
  
  <pre><code>&lt;Window x:Class="ConfigurationViewer.ViewerWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:ConfigurationViewer"
      Title="Configuration Viewer" Height="512" Width="714" &gt;
      &lt;Window.DataContext&gt;
          &lt;local:TaskViewModel x:Name="_model"/&gt;
      &lt;/Window.DataContext&gt;
      &lt;DockPanel&gt;
          &lt;StackPanel DockPanel.Dock="Top" Orientation="Horizontal"&gt;
              &lt;TextBlock Text="Configuration file" Margin="2" VerticalAlignment="Center" /&gt;
              &lt;TextBox Height="29" Margin="2" Name="textFilePath" Width="277" Text="{Binding Path=ConfigurationPath}" /&gt;
              &lt;Button Content="Browse ..." Margin="2" Name="buttonBrowseFile" Width="98" Click="buttonBrowseFile_Click" /&gt;
              &lt;Button Content="Open" Margin="2" Name="buttonOpenFile" Width="98" Click="buttonOpenFile_Click"  /&gt;
          &lt;/StackPanel&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>    public partial class ViewerWindow : Window
      {
          public ViewerWindow()
          {
              InitializeComponent();
          }
  
          private void buttonBrowseFile_Click(object sender, RoutedEventArgs e)
          {
              OpenFileDialog openDialog = new OpenFileDialog();
              openDialog.Multiselect = false;
              openDialog.InitialDirectory = textFilePath.Text;
  
              Nullable&lt;Boolean&gt; ok = openDialog.ShowDialog();
              if (ok == true)
              {
                  textFilePath.Text = openDialog.FileName;
              }
          }
  
          private void buttonOpenFile_Click(object sender, RoutedEventArgs e)
          {
          }
      }
  </code></pre>
  
  <hr>
  
  <pre><code>    public class TaskViewModel : INotifyPropertyChanged
      {
          private String _configurationPath = String.Empty;
          public String ConfigurationPath
          {
              get { return _configurationPath; }
              set
              {
                  _configurationPath = value;
                  OnPropertyChanged("ConfigurationPath");
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          private void OnPropertyChanged(String prop)
          {
              PropertyChangedEventHandler handler = this.PropertyChanged;
              if (handler != null)
              {
                  var e = new PropertyChangedEventArgs(prop);
                  handler(this, e);
              }
          }
      }
  </code></pre>