WPF ScrollViewer 端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15430343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:06:14  来源:igfitidea点击:

WPF ScrollViewer side

c#wpfxamlscrollview

提问by persianLife

I have a Expanderwith a nested ScrollVieweras showm below:

我有一个Expander嵌套ScrollViewer如下所示:

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.

我需要更改 ScrollViewer 的一侧,因此它显示在左侧。

what is the simplest solution to this?

什么是最简单的解决方案?

回答by Simon Bull

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.

您可以自定义滚动查看器的模板以更改滚动条的位置(除其他外)。模板定制的MSDN示例实际上是在展示如何将垂直滚动条向左移动。

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

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>

回答by tequilacat

The scrollbar position is defined by the FlowDirection property.

滚动条位置由 FlowDirection 属性定义。

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

有关更多详细信息,请参阅https://stackoverflow.com/a/22717596/2075605

回答by PeruCode

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

我测试了它,它对我有用