Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As noted in another answer there are probably lots of ways to do this, but here's my simple way:</p> <p>Define a DataTemplate that defines the content of each your identical tabs. The controls in the data template will bind to the view model of the currently selected tab. I've put a single TextBlock in my example but you can easily extend this.</p> <p>using this Xaml:</p> <pre><code>&lt;Page.DataContext&gt; &lt;Samples:TabBindingViewModels /&gt; &lt;/Page.DataContext&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &lt;DataTemplate x:Key="ContentTemplate" DataType="{x:Type Samples:TabBindingViewModel}"&gt; &lt;TextBlock Text="{Binding Content}"/&gt; &lt;/DataTemplate&gt; &lt;/Grid.Resources&gt; &lt;TabControl ContentTemplate="{StaticResource ContentTemplate}" DisplayMemberPath="Header" ItemsSource="{Binding Items}" /&gt; &lt;/Grid&gt; </code></pre> <p>and this view model code:</p> <pre><code>public class TabBindingViewModels { public TabBindingViewModels() { Items = new ObservableCollection&lt;TabBindingViewModel&gt; { new TabBindingViewModel(1), new TabBindingViewModel(2), new TabBindingViewModel(3), }; } public IEnumerable&lt;TabBindingViewModel&gt; Items { get; private set; } } public class TabBindingViewModel { public TabBindingViewModel() : this(0) { } public TabBindingViewModel(int n) { Header = "I'm the header: " + n.ToString(CultureInfo.InvariantCulture); Content = "I'm the content: " + n.ToString(CultureInfo.InvariantCulture); } public string Header { get; set; } public string Content { get; set; } } </code></pre> <p>we get:</p> <p><img src="https://i.stack.imgur.com/kGqbR.png" alt="enter image description here"></p> <p>I quite like this <a href="http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out" rel="nofollow noreferrer">tutorial</a> on styling the tab control. You can easily put more complex content into the tab headers as well as the content.</p> <p>You should examine the full template of the tab control to gain an insight into how it works. Use Blend or VS11 beta to extract the template.</p> <p>In order to dynamically add/delete tabs, now all you need to do is add/delete items to the ObservableCollection of view models.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload