title: How to set up a dynamically-populated TabControl with ReactiveUI?
body: <p>I'm trying to wrap my head around ReactiveUI.  Most of it makes some degree of sense if you don't look at it too closely, but when I try to set up a <code>TabControl</code> everything explodes in my face.</p>
  <p>I have a <code>TabControl</code> on my <code>Window</code>.  I want to be able to add multiple different types of tabs to it dynamically at runtime based on different user actions.  <a href="https://stackoverflow.com/a/8755865/32914">This answer</a> explains a standard WPF way to do that, and it almost works, but since it's not ReactiveUI, anytime I try to open a tab with a Reactive view on it, everything blows up because the <code>ViewModel</code> dependency property hasn't been bound.</p>
  <p>XAML:</p>
  <pre><code>    &lt;Window.Resources&gt;
          &lt;DataTemplate DataType=&quot;{x:Type vm:MyTabViewModel}&quot;&gt;
              &lt;views:MyTabEditor/&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
  ...
          &lt;TabControl Name=&quot;Multitab&quot; Grid.Column=&quot;2&quot; ItemsSource=&quot;{Binding Tabs}&quot;&gt;
              &lt;TabControl.ItemContainerStyle&gt;
                  &lt;Style TargetType=&quot;{x:Type TabItem}&quot;&gt;
                      &lt;Setter Property=&quot;Header&quot; Value=&quot;{Binding Name}&quot; /&gt;
                  &lt;/Style&gt;
              &lt;/TabControl.ItemContainerStyle&gt;
          &lt;/TabControl&gt;
  </code></pre>
  <p>ViewModel:</p>
  <pre><code>        public ObservableCollection&lt;ITabPage&gt; Tabs { get; } = new();
  
          public void AddNewTab()
          {
              var vm = new MyTabEditorViewModel();
              Tabs.Add(vm);
          }
  
  </code></pre>
  <p>XAML.cs</p>
  <pre><code>        private void NewTab_Executed(object sender, ExecutedRoutedEventArgs e)
          {
              ViewModel.AddNewJob();
              Multitab.SelectedIndex = Multitab.Items.Count - 1;
              var last = Multitab.SelectedIndex;
              this.OneWayBind(ViewModel, vm =&gt; vm.Tabs[last], v =&gt; GAH WHAT GOES HERE?!?);
          }
  </code></pre>
  <p>And this is the part where I get lost.  How do I set up the bindings to bind the new VM to the view that gets created for it?  <code>Multitab.SelectedItem</code> returns the VM, not the View, and I can't seem to find any way to obtain the newly-created View object in order to bind it.</p>
  <p>Does anyone know how to set this up properly?</p>