TabItem DataTemplate with binding
<p>I have a <code>TabControl</code> in my app. I'd like to have as many <code>TabItems</code> as many entries are in my dictionary.</p>

<p>Here's my dictionary:</p>

<pre><code>public Dictionary&lt;string , ObservableCollection&lt;PerformanceCounter&gt;&gt; Counters
{
    get { return _Counters; }
}
Dictionary&lt;string, ObservableCollection&lt;PerformanceCounter&gt;&gt; _Counters = new Dictionary&lt;string , ObservableCollection&lt;PerformanceCounter&gt;&gt;();
</code></pre>

<p>Every entry has a string key and ObservableCollection of PerformanceCounter objects. Important thing is the fact that every PerformanceCounter object has properties: CounterName and InstanceName - I'll need these two to display them.</p>

<p>Now, to my XAML:</p>

<pre><code>&lt;TabItem Header="Memory"&gt;
    &lt;Grid Name="RAMGrid"&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width="*"/&gt;
            &lt;ColumnDefinition Width="*"/&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height="1*"/&gt;
            &lt;RowDefinition  Height="Auto"/&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;ListBox Name="RAMListBox" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0" ItemsSource="{Binding Memory, Mode=OneWay}" SelectionMode="Multiple" BorderThickness="1" BorderBrush="#FF8B8B8B" SelectionChanged="RAMListBox_SelectionChanged"&gt;
            &lt;ListBox.ItemTemplate&gt;
                &lt;DataTemplate&gt;
                    &lt;TextBlock&gt;
                        &lt;Run Text="{Binding CounterName, Mode=OneWay}" /&gt;
                        &lt;Run Text="{Binding InstanceName, Mode=OneWay}" /&gt;
                    &lt;/TextBlock&gt;
                &lt;/DataTemplate&gt;
            &lt;/ListBox.ItemTemplate&gt;
        &lt;/ListBox&gt;                                         
        &lt;Button Name="RAMSelectAllButton" Margin="0,10,0,0" Grid.Column="0" Grid.Row="1" Click="RAMSelectAllButton_Click" &gt;
            &lt;TextBlock Text="SELECT ALL"/&gt;
        &lt;/Button&gt;
        &lt;Button Name="RAMUnSelectAllButton" Margin="0,10,0,0" Grid.Column="1" Grid.Row="1" Click="RAMUnSelectAllButton_Click" &gt;
            &lt;TextBlock Text="UNSELECT ALL"/&gt;
        &lt;/Button&gt;
    &lt;/Grid&gt;
&lt;/TabItem&gt;
</code></pre>

<p>That's what I did and, as you might already know, it does not work. The above code is only for one entry of my dictionary, where the key is "Memory".</p>

<p>In my code I set DataContext:</p>

<pre><code>this.DataContext = appData.Counters;
</code></pre>

<p>appData.Counters is that dictionary I presented at the beginning.</p>

<p>Here's what I'd like to achieve:
No matter how many entries there are in my dictionary, my TabControl would display TabItem for each of them.
Each TabItem has a ListBox and 2 buttons. I'll need too be able to access those (in order to clear the list and to have click event for each button).</p>

<p>I really don't know how to do it, I hope you can help me out.</p>