-1

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>
Sascha
  • 37
  • 6
  • 1
    "*so that I can access the sub-values*" - what does that mean? Should all item commands be invoked by a click on the single Button? – Clemens Dec 08 '21 at 08:59
  • @Sascha: Why are you using an `ItemsControl` if you only want to display a single `Button`? – mm8 Dec 08 '21 at 19:32

1 Answers1

1

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>
Slime recipe
  • 2,223
  • 3
  • 32
  • 49
  • Unfortunately it does not work. I still get several buttons instead of just one. – Sascha Dec 08 '21 at 09:00
  • 1
    Of course it does not work. That's because there is an outer – Mike Nakis Dec 08 '21 at 09:06
  • I need the binding of the inner button. Say, I need Rechte.CanDelFPFoer. I cannot access it outside of the ItemsControl. – Sascha Dec 08 '21 at 09:10
  • @Sascha you asked how to "add an Itemsource to a button " the example above does that if. if you have other questions, please submit these separately – Slime recipe Dec 08 '21 at 09:22