WPF - Itemssource in a Button

246 Views Asked by At

everyone, I would like to add an Itemsource to a button so that I can access the sub-values. If I do the whole thing with ItemsControl, I get a button for each value. However, I only need one button. Can i limit this?

My Output: 30 Buttons -> I need 1.

My WPF Code:

<ItemsControl ItemsSource="{Binding Rechte}" >
     <ItemsControl.ItemTemplate>
          <DataTemplate>
               <StackPanel>
                    <Button Content="Löschen"  Command="{Binding FoerderLoeschen}" FontSize="{Binding SelectedFont, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding Rechte.CanDelFPFoer, Converter={StaticResource BoolToVis}}" Padding="5 5 5 5" Margin="5 15 5 0"/>
               </StackPanel>
          </DataTemplate>
     </ItemsControl.ItemTemplate>
</ItemsControl>
1

There are 1 best solutions below

4
Slime recipe On

Wrap the ItemsControl with a button so it becomes the button's content:

 <Button>
   <ItemsControl ItemsSource="{Binding Rechte}" >
     <ItemsControl.ItemTemplate>
          <DataTemplate>
               <StackPanel>
                    <Button Content="Löschen"  Command="{Binding FoerderLoeschen}" FontSize="{Binding SelectedFont, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding Rechte.CanDelFPFoer, Converter={StaticResource BoolToVis}}" Padding="5 5 5 5" Margin="5 15 5 0"/>
               </StackPanel>
          </DataTemplate>
     </ItemsControl.ItemTemplate>
</ItemsControl>
</Button>