C
C#16mo ago
Anton

❔ Preventing a panel from overflowing + show scrollbar WPF

I have a situation like this
<StackPanel>
<Grid>
some buttons
</Grid>
<StackPanel> possibly wrapped in ScrollViewer?
variable height content that may not fit
</StackPanel>
</StackPanel>
<StackPanel>
<Grid>
some buttons
</Grid>
<StackPanel> possibly wrapped in ScrollViewer?
variable height content that may not fit
</StackPanel>
</StackPanel>
The problem is that the bottom panel overflows on the y axis. Solutions online suggest setting it to the width of the container like here https://stackoverflow.com/questions/47333220/wpf-scrollviewer-content-overflowing which I obviously can't do. How do I hide the overflow? I want it to take all available space on the Y axis, but no more than the screen height.
Stack Overflow
WPF - ScrollViewer content overflowing
I have a WPF control with this basic structure: <Grid> <ScrollViewer x:Name="_Scroll" Grid.Row="4" Grid.RowSpan="20" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="
4 Replies
Anton
Anton16mo ago
I think this happens because the outer stack panel grows off the window
<StackPanel
VerticalAlignment="Stretch"
>
<Grid>

</Grid>
<ScrollViewer
HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalAlignment="Stretch"
>
<StackPanel
Orientation="Horizontal"
>
<DataGrid
ItemsSource="{Binding StudentList, Mode=OneTime}"
HorizontalAlignment="Stretch"
AutoGenerateColumns="true"/>
<StackPanel
Name="QueryResultView"
HorizontalAlignment="Stretch"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
<StackPanel
VerticalAlignment="Stretch"
>
<Grid>

</Grid>
<ScrollViewer
HorizontalAlignment="Stretch"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalAlignment="Stretch"
>
<StackPanel
Orientation="Horizontal"
>
<DataGrid
ItemsSource="{Binding StudentList, Mode=OneTime}"
HorizontalAlignment="Stretch"
AutoGenerateColumns="true"/>
<StackPanel
Name="QueryResultView"
HorizontalAlignment="Stretch"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
Like it just overflows on the y axis. It seems like it stretches up to children size and not the outer container size Can I do this without a fixed height on the StackPanel? How can it infer the height from the parent? Setting it like shown in the linked stackoverflow post just collapses it to 0 Even though the vertical stretch is set on the scroll viewer To be clear, I'm trying to bind the height to the scroll viewer's ActualHeight anyone???
Anton
Anton16mo ago
Stack Overflow
ScrollViewer not scrolling in WPF
I am using a scrollviewer control around my stack panel which contains an ItemsControl. When there are many items in the ItemsControl it is suppose to scroll but for some reason it just cuts of the...
Anton
Anton16mo ago
changing it to grid might work
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.