Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a WPF screen in which the scroll bars are displayed in the right and down sides of the screen by default. I need it on the left and top sides of the screen by default.I am using a scrollbarviewer with horizontal/vertical scrollbarvisibility=Auto.
Please help me to display the scroll bars in the starting position of the screen so that user no need to scroll it to see the starting point of the screen.
Thanks in advance.

What I have tried:

<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
Posted
Updated 7-May-18 21:29pm

1 solution

You can move the location of the scrollbar using a ControlTemplate.
MSDN has an example to set the vertical bar on the left: ScrollViewer ControlTemplate Example[^]

To put the horizontal bar on the top, change its Grid.Row to 0 and adjust the row definitions so that the first row is auto. The ScrollContentPresenter goes in row 1.

<Style x:Key="LeftScrollViewer" TargetType="{x:Type ScrollViewer}">
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ScrollViewer}">
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
          </Grid.RowDefinitions>

          <ScrollContentPresenter Grid.Column="1" Grid.Row="1"/>

          <ScrollBar Name="PART_VerticalScrollBar"
            Value="{TemplateBinding VerticalOffset}"
            Maximum="{TemplateBinding ScrollableHeight}"
            ViewportSize="{TemplateBinding ViewportHeight}"
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
          <ScrollBar Name="PART_HorizontalScrollBar"
            Orientation="Horizontal"
            Grid.Column="1"
            Value="{TemplateBinding HorizontalOffset}"
            Maximum="{TemplateBinding ScrollableWidth}"
            ViewportSize="{TemplateBinding ViewportWidth}"
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
          
        </Grid>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900