Silverlight 2 beta 1: ScrollViewer with auto-layout crashes both IE and FF

.NET, Silverlight, Technical stuff, Work
See comments

Update 2: The Silverlight team at Microsoft was able to reproduce the bug, and it has been entered in the bug database. Thanks all for your precious help!!

Update: Apparently this bug is not consistently reproducible. If you get the bug, please enter a comment with your system information. I was able to reproduce on a number of machines and OS, but on some other PCs it works just fine.

Here is an interesting one:

<UserControl x:Class="GalaSoft.SL.ScrollViewerNoCrash.Page"
             xmlns="http://schemas.microsoft.com/client/2007"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Height="300">
    <Grid x:Name="LayoutRoot"
          Background="Green">
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition />
      </Grid.RowDefinitions>
      <ScrollViewer Grid.Row="1"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Disabled">
         <StackPanel Orientation="Horizontal"
                     Height="150">
          <Border Margin="10,5,10,5"
                  BorderBrush="#FFA9A899"
                  BorderThickness="2,2,2,2">
            <Image Source="pic1.png"
                   Stretch="Fill" />
          </Border>
          <Border Margin="10,5,10,5"
                  BorderBrush="#FFA9A899"
                  BorderThickness="2,2,2,2">
            <Image Source="pic2.jpg"
                   Stretch="Fill" />
          </Border>
         </StackPanel>
      </ScrollViewer>
    </Grid>
 </UserControl> 

The code above crashes both Internet Explorer and Firefox (on Windows) when you resize the browser window to let the horizontal scrollbar appear in the scrollviewer. I didn’t test other platforms.

On the other hand, the following code works:

<UserControl x:Class="GalaSoft.SL.ScrollViewerCrash.Page"
             xmlns="http://schemas.microsoft.com/client/2007"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Height="300">
    <Grid x:Name="LayoutRoot"
          Background="Red">
      <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="150" />
      </Grid.RowDefinitions>
      <ScrollViewer Grid.Row="1"
                    HorizontalScrollBarVisibility="Auto"
                    VerticalScrollBarVisibility="Disabled">
        <StackPanel Orientation="Horizontal">
          <Border Margin="10,5,10,5"
                  BorderBrush="#FFA9A899"
                  BorderThickness="2,2,2,2">
            <Image Source="pic1.png"
                   Stretch="Fill" />
          </Border>
          <Border Margin="10,5,10,5"
                  BorderBrush="#FFA9A899"
                  BorderThickness="2,2,2,2">
            <Image Source="pic2.jpg"
                   Stretch="Fill" />
          </Border>
        </StackPanel>
      </ScrollViewer>
    </Grid>
 </UserControl> 

Did you spot the difference? The first Grid (the one that crashes) has the second row’s height set to 150, while the ScrollViewer and its children are all set to Auto. In the second one (the one that works), the Grid is set to Auto, while the StackPanel inside the ScrollViewer has its Height set to 150. The workaround is good enough for now, but I hope it’ll get corrected because I like to layout my grids and then let the auto layout take care of the rest.

Note that both versions work fine in WPF.

Resources
  • Test the crash and non-crash case.
  • Download the source code.

2014-12-08_18-43-41

Previous entry | Next blog entry

Comments for Silverlight 2 beta 1: ScrollViewer with auto-layout crashes both IE and FF