title: WPF - MVVM - UserControl binding
body: <p>I'm trying to realize a simple example of a UserControl, showing in a TextBox the current DateTime, updated four times each second.</p>
  
  <p>I create a simple user control:</p>
  
  <pre><code>&lt;UserControl x:Class="UC.TestUC"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:local="clr-namespace:UC"
               mc:Ignorable="d" 
               d:DesignHeight="50" d:DesignWidth="100"&gt;
      &lt;d:UserControl.DataContext&gt;
          &lt;local:TestUC_VM/&gt;
      &lt;/d:UserControl.DataContext&gt;
      &lt;Grid Background="Azure"&gt;
          &lt;TextBox Text="{Binding TestString}"/&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Where its ViewModel is:</p>
  
  <pre><code>namespace UC
  {
      public class TestUC_VM : INotifyPropertyChanged
      {
          private string _testString;
          public string TestString
          {
              get =&gt; _testString;
              set
              {
                  if (value == _testString) return;
                  _testString = value;
                  OnPropertyChanged();
              }
          }
  
          public TestUC_VM()
          {
              TestString = "Test string.";
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
          void OnPropertyChanged([CallerMemberName] string propertyName = null) =&gt; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>
  
  <p>MainWindow XAML:</p>
  
  <pre><code>&lt;Window x:Class="UC.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:UC"
          mc:Ignorable="d"
          Title="MainWindow" Height="100" Width="200"&gt;
      &lt;Window.DataContext&gt;
          &lt;local:MainWindow_VM/&gt;
      &lt;/Window.DataContext&gt;
      &lt;Window.Resources&gt;
          &lt;local:TestUC_VM x:Key="TestUC_VM"/&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;local:TestUC DataContext="{StaticResource TestUC_VM}"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>And its ViewModel:</p>
  
  <pre><code>namespace UC
  {
      public class MainWindow_VM
      {
          public TestUC_VM _uc_VM;
  
          public MainWindow_VM()
          {
              _uc_VM = new TestUC_VM();
              Task.Run(() =&gt; ChangeString());
          }
  
          public async Task ChangeString()
          {
              while (true)
              {
                  _uc_VM.TestString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                  await Task.Delay(250);
              }
          }
      }
  }
  </code></pre>
  
  <p>Even though I see with debugger that I'm passing through the TestString setter, the MainWindow is not updated.
  I'm quite sure I'm missing something trivial in setting DataContext of UC in MainWindow, but I've not been able to find what after several hours of browsing and thinking.</p>
  
  <p>Any help appreciated.</p>