Bind Collection to StackPanel

后端 未结 1 1640
有刺的猬
有刺的猬 2020-12-02 17:50

I want to take a collection of objects and bind it to a StackPanel so basically if the collection has 4 elements, inside the stack panel that should produce 4 buttons lets s

相关标签:
1条回答
  • 2020-12-02 18:33

    Alright I have figured it out... Using an ItemsControl solved the problem...

    <ItemsControl x:Name="tStack" Grid.Column="0">
       <ItemsControl.ItemsPanel>
          <ItemsPanelTemplate>
             <StackPanel Orientation="Horizontal"/>
          </ItemsPanelTemplate>
       </ItemsControl.ItemsPanel>
       <ItemsControl.ItemTemplate>
          <DataTemplate>
             <Button Content="{Binding ItemName}"/>
          </DataTemplate>
       </ItemsControl.ItemTemplate>
    </ItemsControl>
    
    0 讨论(0)
提交回复
热议问题