title: How can I create a set of ToggleButtons that behave like RadioButtons?
body: <p>I am using C# and WPF and I basically want to have some toggle buttons and only one of them can be selected at the same time.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/2362641/how-to-get-a-group-of-toggle-buttons-to-act-like-radio-buttons-in-wpf">another question</a> about that, but the solution shown there does not work and I don't know why.</p>
  
  <p>If I try to do it as mentioned in the question above, the <code>ItemTemplate</code> of the <code>ListBox</code> is not applied. I just don't get the toggle buttons into the listbox, instead it is shown as a "normal listbox".</p>
  
  <p>My toggle button style looks like this, contained in one of my resource files:</p>
  
  <pre><code>&lt;Style x:Key="ToggleButtonListBox" TargetType="{x:Type ListBox}"&gt;
      &lt;Setter Property="ListBox.ItemTemplate"&gt;
          &lt;Setter.Value&gt;
              &lt;DataTemplate&gt;
                  &lt;ToggleButton Content="{Binding}"
                            IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}" /&gt;
              &lt;/DataTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property="ListBox.ItemsPanel"&gt;
          &lt;Setter.Value&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;StackPanel Orientation="Horizontal" /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property="BorderThickness" Value="0" /&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>I would like to add the items directly in the XAML code, so my code for that would look something like</p>
  
  <pre><code>&lt;ListBox Style="{StaticResource ToggleButtonListBox}"&gt;
      &lt;ListBoxItem&gt;test1&lt;/ListBoxItem&gt;
      &lt;ListBoxItem&gt;test2&lt;/ListBoxItem&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>How can I create such a set of buttons?</p>