gpt4 book ai didi

c# - WPF ScrollViewer 端

转载 作者:行者123 更新时间:2023-11-30 22:19:42 28 4
gpt4 key购买 nike

我有一个带有嵌套 ScrollViewerExpander,如下所示:

代码(简化版)

<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>

我需要更改 ScrollViewer 的一侧,使其显示在左侧。

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

最佳答案

您可以自定义滚动查看器的模板以更改滚动条的位置(以及其他内容)。模板定制的MSDN例子其实就是展示了如何将垂直滚动条向左移动。

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

为方便起见,这里是代码:

<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>

关于c# - WPF ScrollViewer 端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15430343/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com