1

Take this simplistic code:

<Window x:Class="WpfApplication1.Window2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window2" Height="340" Width="600">
    <ScrollViewer>
        <Grid Background="Red" VerticalAlignment="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="20" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Text="1:" />
            <TextBox Grid.Row="0" Grid.Column="1" Height="80" Margin="4" />

            <TextBlock Grid.Row="1" Text="2:" />
            <TextBox Grid.Row="1" Grid.Column="1" Height="80" Margin="4" />

            <TextBlock Grid.Row="2" Text="3:" />

            <TextBlock Grid.Row="3" Grid.Column="0" Text="4.:" />
        </Grid>
    </ScrollViewer>
</Window>

Visual Studio designer shows everything correctly: enter image description here

And yet, during runtime, this is the result: enter image description here

Notice how row nr 4 is no longer inside the Grid?! It is rendered outside of it. Also, if you shorten the window, the vertical scroll bar does become visible, but it only scrolls the red area. It is not possible to scroll to see row 4.

If you remove VerticalAlignment="Top" from the Grid, then the rendering seems to be fixed, but scrolling still does not work properly.

Can anyone explain what on earth is going on? Is it a Microsoft bug?

I'm running Visual Studio 2017 Community edition (fully updated), Win 10 version 1803, which contains .NET 4.7.2.

(I think it is related to .NET 4.7.2, because I've never noticed this problem until now)

There is a workaround, specify - <RowDefinition Height="Auto" /> for all rows, but that should not be necessary...

Marko
  • 2,266
  • 4
  • 27
  • 48
  • there must have been some styles in your solution which affect margins and stuff. I tested this piece of code and designer and runtime are identical. – Bizhan Jul 31 '18 at 18:57
  • @Bijan - no styles anywhere. But your comment made me test this out on a new fresh solution. The problem arises when I change the targeted .NET framework version to 4.7.1. Using 4.6.2 or 4.5.1 works just fine, which is very odd. Considering that the built in 4.7.2 effectively replaces all previous versions. Even if you target 4.6.2 it will still be ran against 4.7.2... – Marko Jul 31 '18 at 19:04
  • 1
    I have this problem on 4.7 as well, just tested it. Perhaps bring this up to the devs on github or the MS forums? – user2619824 Jul 31 '18 at 20:10

1 Answers1

1

This is a bug in the new algorithm for allocating space to *-rows. (An app uses the new algorithm when it targets 4.7+, or when you have installed 4.7+ and have set Switch.System.Windows.Controls.Grid.StarDefinitionsCanExceedAvailableSpace=false.)

The bug was reported earlier (see https://github.com/Microsoft/dotnet/issues/674), and is already fixed in 4.8 (see https://github.com/Microsoft/dotnet-framework-early-access/blob/master/release-notes/NET48/build-3632/dotnet-build-3632-changes.md#wpf).

Sam Bent - MSFT
  • 276
  • 2
  • 5
  • Too bad that it will be again fixed in a future release. This means all developers targeting 4.7.x have to put up with this rubbish. Retest all their windows, lots of manual labor, create version specific workarounds. And once 4.8 hits and you target that, then you have to again redo everything, to undo your workarounds etc. Why Microsoft can't fix such bugs by simply pushing out a hotfix/update to existing .NET versions is beyond me... – Marko Aug 07 '18 at 21:27