我正在尝试复制MS Word的基本界面。我已经创建了文档,在文档周围带有边框以产生阴影效果,并且这两个文档都包含在ScrollViewer中。问题在于ScrollViewer不允许滚动。我要使其完全滚动的唯一方法是,在ScrollViewer上设置ZoomMode="Enabled"
,然后进行放大,在这种情况下,将显示滚动条,并按预期滚动。但是当ZoomMode="Disabled"
或缩小时,没有滚动,没有滚动条,什么也没有。好像ScrollViewer不存在。
我预感这是由ScrollViewer所属的布局控件引起的,但我不知道可能是什么原因。我尝试过在ScrollViewer中更改文档的高度以强制其滚动,但这也没有效果。
有人可以在这里查看XAML,看看他们是否可以找到错误的出处吗?
MainPage XAML
<Page
x:Class="Bartleby.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Bartleby"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Loaded="Page_Loaded"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<SplitView IsPaneOpen="True" DisplayMode="Inline" Background="Gray">
<SplitView.Pane>
<StackPanel>
<TextBlock Text="Book Title" FontSize="24" FontWeight="Bold" />
<ListView>
<ListViewItem Content="Chapter 1" />
<ListViewItem Content="Chapter 2" />
<ListViewItem Content="Chapter 3" />
<ListViewItem Content="Chapter 4" />
<ListViewItem Content="Chapter 5" />
<ListViewItem Content="Chapter 6" />
<Button x:Name="addChapter" Tapped="AddChapter_Tapped"/>
</ListView>
</StackPanel>
</SplitView.Pane>
<Grid HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="916" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1152" />
</Grid.RowDefinitions>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.Resources>
<Style TargetType="AppBarButton">
<Setter Property="IsCompact" Value="True" />
</Style>
</Grid.Resources>
<!--File Handling-->
<AppBarButton x:Name="openFileButton" Grid.Column="0" Icon="OpenFile" ToolTipService.ToolTip="Open file" />
<AppBarButton x:Name="saveFileButton" Grid.Column="1" Icon="Save" ToolTipService.ToolTip="Save file" RelativePanel.RightOf="openFileButton" />
<AppBarSeparator RelativePanel.RightOf="saveFileButton" Grid.Column="2" />
<!--Font Style-->
<AppBarButton x:Name="boldFileButton" Grid.Column="3" Icon="Bold" ToolTipService.ToolTip="Bold" RelativePanel.LeftOf="italicFileButton" />
<AppBarButton x:Name="italicFileButton" Grid.Column="4" Icon="Italic" ToolTipService.ToolTip="Italic" RelativePanel.LeftOf="underlineFileButton" />
<AppBarButton x:Name="underlineFileButton" Grid.Column="5" Icon="Underline" ToolTipService.ToolTip="Underline" RelativePanel.AlignRightWithPanel="True" />
<!--Alignment-->
<AppBarButton x:Name="alignLeftButton" Grid.Column="6" Icon="AlignLeft" ToolTipService.ToolTip="Align left" RelativePanel.RightOf="saveFileButton" />
<AppBarButton x:Name="alignCenterButton" Grid.Column="7" Icon="AlignCenter" ToolTipService.ToolTip="Align center" RelativePanel.RightOf="alignLeftButton" />
<AppBarButton x:Name="alignRightButton" Grid.Column="8" Icon="AlignRight" ToolTipService.ToolTip="Align right" RelativePanel.RightOf="alignCenterButton" />
</Grid>
<ScrollViewer Grid.Row="1" Grid.Column="0" VerticalScrollBarVisibility="Visible" ZoomMode="Disabled" BringIntoViewOnFocusChange="False" Height="600" VerticalAlignment="Top">
<Border Margin="40" HorizontalAlignment="Stretch" >
<local:DocumentView x:Name="editor" DocumentHeight="1056" DocumentWidth="816" PlaceholderText="Text Goes In Here" BorderBrush="Black" />
</Border>
</ScrollViewer>
</Grid>
</SplitView>
</Page>
答案 0 :(得分:1)
尝试一下。这应该工作完美。
<ScrollViewer Grid.Row="1"
Grid.Column="0"
Height="600"
HorizontalScrollMode="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalAlignment="Top">
<!--If the elements don't exceed the size of the box, the scrollbar won't be visible-->
<!--Use your BG color-->
<Border Background="White"
HorizontalAlignment="Stretch" >
<!--Use SPanel or grid or RPanel to include more than one element-->
<StackPanel Margin="10">
<TextBlock x:Name="editor"
TextWrapping="Wrap"
Text="Custom Text more that the screen or the box size"/>
</StackPanel>
</Border>
</ScrollViewer>