title: Why is Datatemplate not working properly?
body: <p>I use the code below to display the data, but the result seems to show the ToString() method of the object.</p>
  <p>It seems to be failing to recognize that Model is of type model.</p>
  <p>I looked at the solution <a href="https://stackoverflow.com/a/15484824/15181473">here</a>. My code should work.</p>
  <p>Why is the data not showing? What did i do wrong?</p>
  <p>Xaml:</p>
  <pre><code>  &lt;Window.DataContext&gt;
          &lt;local:MainWindowViewModel/&gt;
      &lt;/Window.DataContext&gt;
      &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key=&quot;DT&quot; DataType=&quot;{x:Type local:model}&quot;&gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width=&quot;200&quot;/&gt;
                      &lt;ColumnDefinition Width=&quot;200&quot;/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height=&quot;50&quot;/&gt;
                      &lt;RowDefinition Height=&quot;50&quot;/&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;TextBlock Grid.Row=&quot;0&quot; Grid.Column=&quot;0&quot;&gt;Id&lt;/TextBlock&gt;
                  &lt;TextBlock Grid.Row=&quot;0&quot; Grid.Column=&quot;1&quot; Text=&quot;{Binding Id}&quot;&gt;&lt;/TextBlock&gt;
                  &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;0&quot;&gt;Name&lt;/TextBlock&gt;
                  &lt;TextBlock Grid.Row=&quot;1&quot; Grid.Column=&quot;1&quot; Text=&quot;{Binding Name}&quot;&gt;&lt;/TextBlock&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
      &lt;StackPanel&gt;
          &lt;ContentControl Width=&quot;400&quot; Content=&quot;{Binding Path=Model}&quot;  /&gt;
      &lt;/StackPanel&gt; 
  </code></pre>
  <p>Codebehind:</p>
  <pre><code>public class model : ViewModelBase
    {
      private string name;
      public string Name
      {
        get { return name; }
        set
        {
          name = value;
          this.OnPropertyChanged(&quot;Name&quot;);
        }
      }
      private int id;
      public int Id
      {
        get { return id; }
        set
        {
          id = value;
          this.OnPropertyChanged(&quot;Id&quot;);
        }
      }
    
    }
  
    public class ViewModelBase : INotifyPropertyChanged
    {
      public event PropertyChangedEventHandler PropertyChanged;
  
      protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
      {
        var handler = PropertyChanged;
        if (handler != null)
          handler(this, new PropertyChangedEventArgs(propertyName));
      }
    }
    public class MainWindowViewModel : ViewModelBase
    { 
      private model model;
      public model Model
      {
        get { return model; }
        set
        {
          model=value;
          this.OnPropertyChanged(&quot;Model&quot;);
        }
      }
      public MainWindowViewModel()
      {
        Model = new model() { Id = 5, Name = &quot;John&quot; };
      }
    }
  </code></pre>
  <p>The result is as follows：</p>
  <p><a href="https://i.stack.imgur.com/w9mNv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w9mNv.png" alt="enter image description here" /></a></p>