title: Catel setting DataContext for nested view
body: <p>Please help me with a problem. Why is the constructor with the signature does not work. And how to determine DataContext for ServerTabView? As I understand, now DataContext for ServerTabView inherited from a parent - MainWindowView, because ServerTabView is nested in it. Then how to get the right to receive ServerTabView DataContext?</p>
  
  <p><code>MainWindowView</code>:</p>
  
  <pre><code>&lt;catel:DataWindow x:Class="ServerUI.Views.MainWindowView"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:catel="http://catel.codeplex.com"
                xmlns:views="clr-namespace:ServerUI.Views"
                Width="640"
                Height="480"
                ResizeMode="CanResize"
                ShowInTaskbar="True"
                SizeToContent="Manual"
                WindowStartupLocation="Manual"
                WindowState="Normal"&gt;
  
  &lt;!--  Resources  --&gt;
  &lt;catel:DataWindow.Resources /&gt;
  
  &lt;catel:TabControl TabStripPlacement="Left"&gt;
      &lt;TabItem Header="__Server__"&gt;
          &lt;views:ServerTabView DataContext="{Binding}" /&gt;
      &lt;/TabItem&gt;
      &lt;TabItem Header="__Clients_"&gt;
          &lt;views:ClientsTabView DataContext="{Binding}" /&gt;
      &lt;/TabItem&gt;
  &lt;/catel:TabControl&gt;
  
  &lt;/catel:DataWindow&gt;
  </code></pre>
  
  <p><code>ServerTabView</code>:</p>
  
  <pre><code>&lt;catel:UserControl x:Class="ServerUI.Views.ServerTabView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:catel="http://catel.codeplex.com"&gt;
  
  &lt;catel:StackGrid&gt;
      &lt;catel:StackGrid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="Auto" /&gt;
      &lt;/catel:StackGrid.RowDefinitions&gt;
  
      &lt;catel:StackGrid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="Auto" /&gt;
          &lt;ColumnDefinition Width="Auto" /&gt;
      &lt;/catel:StackGrid.ColumnDefinitions&gt;
  
      &lt;Label Content="IP Address" /&gt;
      &lt;TextBox Text="{Binding ServerIpAddress}" /&gt;
  
      &lt;Label Content="Port" /&gt;
      &lt;TextBox Text="{Binding ServerPort}" /&gt;
  
      &lt;Label Content="Directory" /&gt;
      &lt;TextBox Text="{Binding Catalogue}" /&gt;
  
      &lt;catel:EmptyRow /&gt;
  
      &lt;Button Grid.ColumnSpan="2"
              Command="{Binding StartServer}"
              Content="Start" /&gt;
  
      &lt;Button Grid.ColumnSpan="2"
              Command="{Binding StopServer}"
              Content="Stop" /&gt;
  &lt;/catel:StackGrid&gt;
  
  &lt;/catel:UserControl&gt;
  </code></pre>
  
  <p><code>ServerTabViewModel</code>:</p>
  
  <pre><code>    public class ServerTabViewModel : ViewModelBase
      {
          private readonly IServerServices _serverServices;
  
          public ServerTabViewModel(Server server, IServerServices serverServices)
          {
              Argument.IsNotNull(() =&gt; serverServices);
              Argument.IsNotNull(() =&gt; server);
  
              _serverServices = serverServices;
              Server = server;
  
              StartServer = new TaskCommand(OnStartServerExecuteAsync);
              StopServer = new TaskCommand(OnStopServerExecuteAsync);
          }
  
          #region Properties
          /// &lt;summary&gt;
          /// Gets or sets the property value.
          /// &lt;/summary&gt;
          [Model]
          public Server Server
          {
              get { return GetValue&lt;Server&gt;(ServerProperty); }
              set { SetValue(ServerProperty, value); }
          }
          // ModelToViewModel Properties
          //...
     }
  </code></pre>
  
  <p>And some debug inormation:</p>
  
  <pre><code>11:57:00:464 =&gt; [DEBUG] [Catel.MVVM.Providers.LogicBase] [10] DataContext of TargetView 'ServerTabView' has changed to 'MainWindowViewModel'
  11:57:00:466 =&gt; [DEBUG] [Catel.MVVM.Providers.LogicBase] [10] Using IViewModelFactory 'Catel.MVVM.ViewModelFactory' to instantiate the view model
  11:57:00:466 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Creating instance of type 'ServerUI.ViewModels.ServerTabViewModel' using specific parameters. No constructor found in the cache, so searching for the right one
  11:57:00:467 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Checking if constructor 'public ctor(Server server, IServerServices serverServices)' can be used
  11:57:00:468 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Constructor is not valid because value 'ServerUI.ViewModels.MainWindowViewModel (ID = 1)' cannot be used for parameter 'ServerUI.ViewModels.MainWindowViewModel (ID = 1)'
  11:57:00:468 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] The constructor is valid and can be used
  11:57:00:469 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] No constructor could be used, cannot construct type 'ServerUI.ViewModels.ServerTabViewModel' with the specified parameters
  11:57:00:469 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Creating instance of type 'ServerUI.ViewModels.ServerTabViewModel' using specific parameters. No constructor found in the cache, so searching for the right one
  11:57:00:469 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Checking if constructor 'public ctor(Server server, IServerServices serverServices)' can be used
  11:57:00:470 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] Constructor is not valid because parameter 'server' cannot be resolved from the dependency resolver
  11:57:00:470 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] The constructor is valid and can be used
  11:57:00:470 =&gt; [DEBUG] [Catel.IoC.TypeFactory] [10] No constructor could be used, cannot construct type 'ServerUI.ViewModels.ServerTabViewModel' with the specified parameters
  11:57:00:471 =&gt; [DEBUG] [Catel.MVVM.ViewModelFactory] [10] Could not construct view model 'ServerUI.ViewModels.ServerTabViewModel' using injection of data context 'MainWindowViewModel'
  11:57:00:471 =&gt; [DEBUG] [Catel.MVVM.Providers.LogicBase] [10] Used IViewModelFactory to instantiate view model, the factory did NOT return a valid view model
  System.Windows.Data Error: 3 : Cannot find element that provides DataContext. BindingExpression:(no path); DataItem=null; target element is 'ClientsTabView' (Name=''); target property is 'DataContext' (type 'Object')
  </code></pre>
  
  <p>How result - <code>ServerTabViewModel(Server server, IServerServices serverServices)</code> dont fireup.</p>
  
  <p><strong>Update</strong>_____________________________________________________________________</p>
  
  <p><code>MainWindowViewModel</code></p>
  
  <pre><code>public class MainWindowViewModel : ViewModelBase
  {
      public MainWindowViewModel()
      {
      }
  
      public override string Title =&gt; "WatcherServerUI";
  }
  </code></pre>
  
  <p>How should i instantiate <code>Server</code> here? I mean, what is good approach for this?</p>