2

ScrollViewer我的 Windows Store 应用程序中的组件遇到了一个奇怪的问题。它内部有一个RichTextColumns可以水平滚动的列中显示文本。

我使用属性启用了缩放ZoomMode="Enabled",但是当我在缩放时松开手指(停止动作)时,滚动平滑到顶部(因此,如果我想缩放一列文本的底部,应用程序会自动移动到顶部,我看不到所需的文字)。

起初,我认为这是捕捉点的问题,但在属性中设置VerticalSnapPointsType="None"和并不能解决问题。ZoomSnapPointsType="None"ScrollViewer

这是代码(与您可以使用名为“Grid application”的默认模板在 Visual Studio 中创建一个新项目相同 [ Aplicación de cuadrícula in spanish]):

<ScrollViewer x:Name="scrollViewer" Style="{StaticResource HorizontalScrollViewerStyle}" Grid.Row="1" ZoomMode="Enabled" VerticalScrollMode="Enabled" VerticalSnapPointsType="None" ZoomSnapPointsType="None" VerticalSnapPointsAlignment="Far" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
      <common:RichTextColumns x:Name="richTextColumns" Margin="117,0,117,47">
          <RichTextBlock x:Name="richTextBlock" Width="560" Style="{StaticResource ItemRichTextStyle}" IsTextSelectionEnabled="False">
                <Paragraph>
                     <Run FontSize="26.667" FontWeight="Light" Text="{Binding Title}"/>
                     <LineBreak/>
                     <LineBreak/>
                     <Run FontWeight="Normal" Text="{Binding Subtitle}"/>
                </Paragraph>
                <Paragraph LineStackingStrategy="MaxHeight">
                     <InlineUIContainer>
                          <Image x:Name="image" MaxHeight="480" Margin="0,20,0,10" Stretch="Uniform" Source="{Binding Image}" AutomationProperties.Name="{Binding Title}"/>
                     </InlineUIContainer>
                </Paragraph>
                <Paragraph>
                     <Run FontWeight="SemiLight" Text="{Binding Content}"/>
                </Paragraph>
          </RichTextBlock>

          <common:RichTextColumns.ColumnTemplate>
               <DataTemplate>
                      <RichTextBlockOverflow Width="560" Margin="80,0,0,0">
                            <RichTextBlockOverflow.RenderTransform>
                                  <TranslateTransform X="-1" Y="4"/>
                            </RichTextBlockOverflow.RenderTransform>
                      </RichTextBlockOverflow>
               </DataTemplate>
          </common:RichTextColumns.ColumnTemplate>
    </common:RichTextColumns>

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ApplicationViewStates">
            <VisualState x:Name="FullScreenLandscape"/>
            <VisualState x:Name="Filled"/>

            <VisualState x:Name="FullScreenPortrait">
                 <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextColumns" Storyboard.TargetProperty="Margin">
                           <DiscreteObjectKeyFrame KeyTime="0" Value="97,0,87,57"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="MaxHeight">
                          <DiscreteObjectKeyFrame KeyTime="0" Value="400"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
            <VisualState x:Name="Snapped">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextColumns" Storyboard.TargetProperty="Margin">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="17,0,17,57"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="scrollViewer" Storyboard.TargetProperty="Style">
                          <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource VerticalScrollViewerStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="richTextBlock" Storyboard.TargetProperty="Width">
                         <DiscreteObjectKeyFrame KeyTime="0" Value="280"/>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="image" Storyboard.TargetProperty="MaxHeight">
                         <DiscreteObjectKeyFrame KeyTime="0" Value="160"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</ScrollViewer>

但是,当我将属性设置VerticalScrollBarVisibilityEnabled( AutoHidden等) 时,缩放按预期工作,但文本显示在单列中(垂直溢出)。文本必须显示在多列中。

我错过了什么?我怎样才能使它与列一起工作?

先感谢您。

4

0 回答 0