0

I'm new to WPF and I find it a bit difficult to understand the Scroll Viewer.

My application is going to run in a 1080x1920 (Portrait mode).

I'm developing the code in a laptop where when I run the project the whole screen is not visible. So I wanted to add a Vertical scroll bar to this Grid, the scroll bar is visible but it doesn't scroll in my laptop.

<Grid>
<StackPanel Style="{StaticResource TabbedInsideStackPanelStyle}" Height="1450">
    <StackPanel Orientation="Horizontal" Style="{StaticResource StackPanelStyle}">
        <TextBlock Text="Enter the Speed" Style="{StaticResource LabelStyle}"/>
        <TextBox x:Name="SpeedTextBox" FontSize="28" Width="100" Margin="10,0,0,0" LostFocus="SpeedTextBox_LostFocus"></TextBox>
    </StackPanel>
<!--Multiple Stack panels-->
</Grid>

Here is the code I tried to bring up the Vertical scrollbar. But it doesn't work good.

<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden">
<Grid>
<StackPanel Style="{StaticResource TabbedInsideStackPanelStyle}" Height="1450">
    <StackPanel Orientation="Horizontal" Style="{StaticResource StackPanelStyle}">
        <TextBlock Text="Enter the Speed" Style="{StaticResource LabelStyle}"/>
        <TextBox x:Name="SpeedTextBox" FontSize="28" Width="100" Margin="10,0,0,0" LostFocus="SpeedTextBox_LostFocus"></TextBox>
    </StackPanel>
<!--Multiple Stack panels-->
</Grid>
</ScrollViewer>

EDIT: The complete skeleton of my code where the above grid exists.

<Window x:Class="TestWindow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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"
        xmlns:local="clr-namespace:TestWindow"
        Title="Test Window" Height="1850" Width="1080"
        WindowStartupLocation="CenterScreen">

    <StackPanel>
        <TabControl Margin="0,10,0,0">
            <TabItem Header="Speed Control" Style="{StaticResource DefaultTabItem}">
                <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden">
                    <Grid>
                        <StackPanel Style="{StaticResource TabbedInsideStackPanelStyle}" Height="1450">
                            <StackPanel Orientation="Horizontal" Style="{StaticResource StackPanelStyle}">
                                <TextBlock Text="Enter the Speed" Style="{StaticResource LabelStyle}"/>
                                <TextBox x:Name="SpeedTextBox" FontSize="28" Width="100" Margin="10,0,0,0" LostFocus="SpeedTextBox_LostFocus"></TextBox>
                            </StackPanel>
                        <!--Multiple Stack panels-->
                    </Grid>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </StackPanel>
</Window>

Please share your suggestions. Thank you.

killer
  • 121
  • 1
  • 10
  • is `ScrollViewer` itself nested in some other container (Grid, StackPanel)? that container might be the problem – ASh Nov 02 '17 at 18:45
  • Ya, I updated the complete skeleton of the code. Pls see the edit section. @ASh – killer Nov 02 '17 at 18:56
  • top level `StackPanel` from updated sample is the problem (``). It allows infinite height for content. ScrollViewer vertical scroll is partially hidden if window is small (bottom `[v]` button is not visible) – ASh Nov 02 '17 at 19:02
  • Ya I tried that code as well. I could see the Scrollbar but it doesn't scroll down or up. Even though I could see only half of it in my laptop screen. – killer Nov 02 '17 at 20:39

0 Answers0