C
C#15mo ago
Seth

XAML Handling sizing between Stackpanel and inner ItemsControl problem (Vertical Alignment Stretch)

Hello, I am new to WPF and XAML and am running into a sizing/layout issue. If you see any faults in my approach please feel free to comment better ideas, trying to get better at WPF as quick as possible for my job. Problem: an ItemsControl that is displaying my ListView and its contents dynamically is not stretching vertically properly. Works as expected when I remove the ItemsControl which is not good as I do not Goal: I am trying to create a functionality in which multiple ListViews will be displayed horizontally. I want the Listviews to be vertically stretched so that when I resize the window, the middle UserControl View of my application expands to reveal more info. Code: - With ItemsControl (Is failing): https://hatebin.com/dqrmhcjpya see image 1 - Without ItemsControl (Is Working) https://hatebin.com/tvjmlcywhg see image 2
6 Replies
JakenVeina
JakenVeina15mo ago
so, you want a list of ListViews with the ListViews laid-out horizontally and the items within them laid-out vertically
Seth
SethOP15mo ago
^Correct
JakenVeina
JakenVeina15mo ago
well, for starters, your StackPanel isn't accomplishing anything it only has one item what you're probably looking for is....
<ItemsControl ItemsSource="{Binding NavigationBoxes}" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel VerticalAlignment="Stretch" CanHorizontallyScroll="True" Orientation="Horizontal" Background="#23292D" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ListView VerticalAlignment="Stretch" Width="200" Background="Red" ItemsSource="{Binding BoxItems}" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding NavigationBoxes}" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel VerticalAlignment="Stretch" CanHorizontallyScroll="True" Orientation="Horizontal" Background="#23292D" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ListView VerticalAlignment="Stretch" Width="200" Background="Red" ItemsSource="{Binding BoxItems}" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Seth
SethOP15mo ago
Thanks this worked - so the ItemsPanelTemplate is what arranges the items inside an Item Control? I havent seen a ItemsPanelTemplate yet so not sure what that is doing
JakenVeina
JakenVeina15mo ago
yes, exactly
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server