locked
Scrollviewer control vertical height doesn't return to original size when switching between portrait and landscape

    Question

  • When I switch screen orientation in the simulator, in portrait mode, the controls get moved down to fill the available space, but when I switch back to landscape mode, they remain at the bottom, or stretched - they don't return to the original position which they started. I would expect since they are being moved to accommodate the portrait mode, that the same mechanism would do the reverse when switching back to the original orientation. But its not.

    EDIT: It looks like my main control (StackPanel) which contains the others, has Height set to Auto.  So when I switch to portrait, the height gets extended, but then I switch back its as if the height remains extended, it doesn't shrink back.

    Any one know how to fix this?




    • Edited by Sal_S Tuesday, April 29, 2014 11:41 PM
    Monday, April 28, 2014 2:55 AM

Answers

  • I think setting these for scroll viewer fixes it

    VerticalScrollMode="Disabled"
    VerticalScrollBarVisibility="Disabled"

    • Marked as answer by Sal_S Tuesday, April 29, 2014 11:55 PM
    Tuesday, April 29, 2014 11:55 PM

All replies

  • I am sure this is not the reason, there has to be something in how your Visual States are done and may be any custom/user/third party controls you may have on screen.

    Please post a working sample of code that has this issue, only then someone will be able to to give you guidance.


    -- Vishal Kaushik --

    Please 'Mark as Answer' if my post answers your question and 'Vote as Helpful' if it helps you. Happy Coding!!!

    Monday, April 28, 2014 3:42 AM
  • This is my XAML

    <Page
        x:Class="MyApp_WindowsStore.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:bm="using:Bing.Maps"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:MyApp_WindowsStore"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      
        mc:Ignorable="d" >
    
        <Grid Height="Auto">
            <Grid.Background>
                <ImageBrush ImageSource="Assets/Backgrounds/wallpaper.jpg" AlignmentX="Left"/>
            </Grid.Background>
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Canvas Grid.Row="0">
                <Canvas.ZIndex>
                    1
                </Canvas.ZIndex>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <!--<Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                            Style="{StaticResource NavigationBackButtonNormalStyle}"
                            VerticalAlignment="Top"
                            AutomationProperties.Name="Back"
                            AutomationProperties.AutomationId="BackButton"
                            AutomationProperties.ItemType="Navigation Button"/>-->
    
                    <TextBlock Grid.Column="1"  x:Name="pageTitle" Text="App Title" Style="{StaticResource HeaderTextBlockStyle}"  
                            IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,50,30,0" >
    
                    </TextBlock>
    
                </Grid>
            </Canvas>
            <ScrollViewer Grid.Row="1" Margin="0,-140,0,0"  VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Hidden" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible">
    
                <!--<StackPanel FlowDirection="LeftToRight" Orientation="Horizontal" >-->
                <Grid x:Name="MainGrid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    
                    <Grid Width="1024" Grid.Column="0">
                        <Canvas>
                            <Canvas.ZIndex>
                                1
                            </Canvas.ZIndex>
                            <TextBlock Text="Current" FontSize="32" Margin="117,130,0,0"  ></TextBlock>
                        </Canvas>
                        <StackPanel FlowDirection="LeftToRight" Orientation="Horizontal" VerticalAlignment="Bottom">
                            <Grid Height="400" Width="400" HorizontalAlignment="Left" VerticalAlignment="Top">
                                <Border Margin="-20,0,0,0" HorizontalAlignment="Left"  Width="300" Height="35"  BorderThickness="0.5" RenderTransformOrigin="0.5,0.5" BorderBrush="{Binding Path=PlotColor, Mode=OneWay}"  UseLayoutRounding="False" d:LayoutRounding="Auto">
                                    <Border.RenderTransform>
                                        <CompositeTransform Rotation="270"/>
                                    </Border.RenderTransform>
                                    <ProgressBar Margin="0,-1.5,0,0" Style="{StaticResource ProgressBarStyle1}" Value="{Binding Path=Current, Mode=OneWay}" Foreground="{Binding Path=PlotColor, Mode=OneWay}" RenderTransformOrigin="0.5,0.5" >
    
                                    </ProgressBar>
                                </Border>
    
                            </Grid>
                            <Grid Height="400" Width="400"  HorizontalAlignment="Left">
    
                            </Grid>
                        </StackPanel>
                    </Grid>
    
                    <Grid Width="900" Grid.Column="1">
                        <Grid.Background>
                            <SolidColorBrush Color="#FF0E0D23" Opacity="0.95"/>
                        </Grid.Background>
                        <Canvas>
                            <Canvas.ZIndex>
                                1
                            </Canvas.ZIndex>
                            <TextBlock Text="Forecast" FontSize="32" Margin="50,130,0,0"  ></TextBlock>
                        </Canvas>
                    </Grid>
                    <Grid Width="900" Margin="0,0,0,0" Grid.Column="2">
                        <Grid.Background>
                            <SolidColorBrush Color="#FF0E0D23" Opacity="0.95"/>
                        </Grid.Background>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="140"></RowDefinition>
                            <RowDefinition ></RowDefinition>
                        </Grid.RowDefinitions>
                        <Canvas>
                            <Canvas.ZIndex>
                                1
                            </Canvas.ZIndex>
                            <TextBlock Text="Location" FontSize="32" Margin="50,130,0,0"  ></TextBlock>
    
                        </Canvas>
                        <Grid Grid.Row="1" Margin="50,50,0,0" Width="700" HorizontalAlignment="Left">
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition Height="200"></RowDefinition>
                            </Grid.RowDefinitions>
    
                            <bm:Map Grid.Row="0"  Margin="0,0,0,0" Credentials="" x:Name="myMap"   ></bm:Map>
                            <Button Grid.Row="1" Width="75" Height="75"></Button>
                        </Grid>
    
                    </Grid>
    
                </Grid>
            </ScrollViewer>
        </Grid>
    </Page>




    • Edited by Sal_S Tuesday, April 29, 2014 4:43 AM
    Tuesday, April 29, 2014 3:50 AM
  • I think setting these for scroll viewer fixes it

    VerticalScrollMode="Disabled"
    VerticalScrollBarVisibility="Disabled"

    • Marked as answer by Sal_S Tuesday, April 29, 2014 11:55 PM
    Tuesday, April 29, 2014 11:55 PM