peterh
Topic Author
Posts: 39
Joined: 13 Mar 2015, 13:50

Grid grows when content grows, but does not shrink when content shrinks.

02 Jun 2021, 14:38

I have a ScrollViewer ControlTemplate that looks like this (simplified for readability):
<ControlTemplate TargetType="{x:Type ScrollViewer}">
  <Grid>
    <DockPanel>
      <ScrollViewer>
        <GridViewHeaderRowPresenter />
      </ScrollViewer>
      <ScrollContentPresenter 
        Name="PART_ScrollContentPresenter" 
        />
    </DockPanel>
    <ScrollBar 
      Name="PART_VerticalScrollBar"
      HorizontalAlignment="Right"
      />
  </Grid>
</ControlTemplate>
The ScrollViewer is used inside a ListView/GridView, and PART_ScrollContentPresenter displays the columns. If PART_ScrollContentPresenter grows (e.g. show hidden column), the Grid grows with it, so everything is displayed correctly. However if PART_ScrollContentPresenter shrinks, the Grid stays the same size, leaving a gap between PART_ScrollContentPresenter and PART_VerticalScrollbar.

How can I get the Grid to properly follow the size of its contents?
 
KeldorKatarn
Posts: 193
Joined: 30 May 2014, 10:26

Re: Grid grows when content grows, but does not shrink when content shrinks.

02 Jun 2021, 15:22

Why is there a scrollviewer inside your scrollviewer template?
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Grid grows when content grows, but does not shrink when content shrinks.

04 Jun 2021, 10:52

Hi peter, could you please report this in our bugtracker. I'm seeing this behavior also in our default template for the ListView so there must be a bug.
Why is there a scrollviewer inside your scrollviewer template?
This is the template for the scrollviewer used in the ListView, and the inner ScrollViewer is to allow horizontal scrolling in the column headers as they are not part of the item rows.

Who is online

Users browsing this forum: Google [Bot] and 74 guests