Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto SizeToContent + MaxHeight + ScrollViewer dont adapt well and cut contents #6441

Closed
sn4k3 opened this issue Aug 18, 2021 · 0 comments · Fixed by #8095
Closed

Auto SizeToContent + MaxHeight + ScrollViewer dont adapt well and cut contents #6441

sn4k3 opened this issue Aug 18, 2021 · 0 comments · Fixed by #8095
Labels

Comments

@sn4k3
Copy link
Contributor

sn4k3 commented Aug 18, 2021

Describe the bug
I'm always fighting the Auto SizeToContent system, and need to apply dirty hacks for the content to really adjust and be visible.
I do tool windows with SizeToContent="WidthAndHeight" and then i limit the MaxHeight to be the screen resolution less a margin, so the windows can constrain to the screen and never go out. So far so good, then i just put a ScrollViewer for content and expect it to work, the problem is it will never work as expected after Height hit MaxHeight and scroll is required.

Note the cut content and scroll viewport not properly calculated:
image

I think i'm not doing something that outrageous/complex on this window, but everytime i use SizeToContent and try to play with Auto and Fills things never go right when MaxWidth/Height is set. I think this need a serious review as this bug is here from long term...
However if you able to resize the window, even 1px less will auto fix the viewport and get the all content to show within the scrollviewer. But it should work without allow CanResin and user have to colapse and expand the window to content to adapt.

Not only this but there are other elements that break things, for example TabControl, when switch tabs on a system that is not Windows, the window will not auto resize. #4896

Also there are more problems, if you have a control.IsVisible = false when window spawn, setting it to true after will not make scroll to adapt. But this may be related with my main problem.

To Reproduce

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaAutoHeightBug.Test1Window"
        Title="Test1Window"
        CanResize="False"
        Width="400"
        SizeToContent="Height"
        MaxHeight="800"
        >

    <Grid RowDefinitions="Auto,*,Auto">
        <Border Grid.Row="0" Background="Gray" Height="50">
            <TextBlock Text="Header" FontWeight="Bold" 
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"/>
        </Border>

        <Border Grid.Row="1" Background="LightGray">
            <ScrollViewer>
                <Grid RowDefinitions="Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto,100,Auto">
                  <TextBlock Grid.Row="0" Text="Spacing 1"/>
                  <TextBlock Grid.Row="2" Text="Spacing 2"/>
                  <TextBlock Grid.Row="4" Text="Spacing 3"/>
                  <TextBlock Grid.Row="6" Text="Spacing 4"/>
                  <TextBlock Grid.Row="8" Text="Spacing 5"/>
                  <TextBlock Grid.Row="10" Text="Spacing 6"/>
                  <TextBlock Grid.Row="12" Text="Spacing 7"/>
                  <TextBlock Grid.Row="14" Text="Spacing 8"/>
                  <TextBlock Grid.Row="16" Text="Spacing 9"/>
                  <TextBlock Grid.Row="18" Text="Spacing 10"/>
                  <TextBlock Grid.Row="20" Text="Spacing 11"/>
                  <TextBlock Grid.Row="22" Text="Spacing 12"/>
                  <TextBlock Grid.Row="24" Text="Spacing 13"/>
                  <TextBlock Grid.Row="26" Text="Spacing 14"/>
              </Grid>
            </ScrollViewer>
        </Border>

        <Border Grid.Row="2" Background="Gray" Height="50">
            <TextBlock Text="Footer" FontWeight="Bold"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"/>
        </Border>
    </Grid>

  </Window>

Expected behavior
image

Desktop (please complete the following information):

  • OS: This happen on every OSes i tried
  • Version 0.10.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant