2

I have a Expander with a nested ScrollViewer as showm below:

Code (simplified version)

<Expander.Content> <ScrollViewer VerticalScrollBarVisibility="Auto" > <StackPanel Orientation="Vertical"> <TextBox FontSize="16" BorderThickness="0" IsReadOnly="True" Background="Transparent" Foreground="MidnightBlue" TextWrapping="Wrap" Text="{Binding LoggingMessage, Mode=OneWay}"> </TextBox> /StackPanel> </ScrollViewer> </Expander.Content> </Expander> 

I need to change the side of the ScrollViewer, so its shown on the LEFT side.

what is the simplest solution to this?

1
  • if you don't mind that the text is right aligned, you can set the FlowDirection of the ScrollViewer to RightToLeft, which will put the scrollbar on the left side. Commented Mar 15, 2013 at 11:25

3 Answers 3

6

You can customize the template of the scrollviewer to change the position of the scrollbar(s) (among other things). The MSDN example of template customisation is actually showing how to move the vertical scrollbar to the left.

http://msdn.microsoft.com/en-gb/library/aa970847(v=vs.85).aspx

Here is the code for convenience:

<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/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ScrollContentPresenter Grid.Column="1"/> <ScrollBar Name="PART_VerticalScrollBar" Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/> <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 
Sign up to request clarification or add additional context in comments.

Comments

2

The scrollbar position is defined by the FlowDirection property.

See https://stackoverflow.com/a/22717596/2075605 for more details

Comments

0

The above code is to change from right to left. However, you need from left to Right. Use same code as above but change the scrollcontent presenter to this:

<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Grid.Column="0" Grid.Row="0"/> 

$

I tested it and it worked for me

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.