[MVVM] How to bind a collection to a StackPanel instead of a ListBox? #15967
-
It's hard to explain this in words, so let me show an example. This is what I currently have: <ListBox ItemsSource="{Binding Games}" Background="Transparent">
<ListBox.ItemTemplate>
<DataTemplate>
<views:GameControl DataContext="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> And I'd like to turn it into something like: <StackPanel ItemsSource="{Binding Games}" Orientation="Vertical">
<StackPanel.ItemTemplate>
<DataTemplate>
<views:GameControl DataContext="{Binding}" />
</DataTemplate>
</StackPanel.ItemTemplate>
</StackPanel> How do I achieve that? |
Beta Was this translation helpful? Give feedback.
Answered by
stevemonaco
Jun 9, 2024
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
slxdy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
StackPanel
isn't a collection control, it's a layout control. I'm guessing that you don't want selection in which case you should useItemsControl
instead. You can replace theItemsPanel
of a collection control, butItemsControl
already has aStackPanel
as its default.