2016-11-30 26 views
0

我创建了一个UserControl,它包含一个ScrollViewer,一个StackPanel和两个按钮。我已禁用水平滚动条并希望使用按钮滚动。但是当我在控件中设置Horizo​​ntalSnapPointsType时,它不起作用。如果我将ScrollViewer直接添加到我的主xaml中,则该属性已设置。像Horizo​​ntalScrollBarVisibility和Horizo​​ntalScrollMode其他属性设置正确,所以我不知道问题是什么。我已经在下面包含了xaml。UWP中的Horizo​​ntalSnapPointsType ScrollViewer UserControl未设置

<UserControl 
x:Class="TestApp.Controls.CarouselScrollViewer" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:TestApp.Controls" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="300" 
d:DesignWidth="400"> 

<Grid> 
    <ScrollViewer x:Name="ScrollViewer" 
      HorizontalScrollBarVisibility="Hidden" 
      HorizontalScrollMode="Disabled" 
      VerticalScrollBarVisibility="Hidden" 
      VerticalScrollMode="Disabled" 
      HorizontalSnapPointsType="Mandatory"> 
     <ContentPresenter x:Name="Content" Content="{x:Bind ScrollViewerContent}" /> 
    </ScrollViewer> 
    <Button VerticalAlignment="Center" HorizontalAlignment="Left" Content="LEFT" Background="White" Click="LeftButton_OnClick" Name="BtnLeft"/> 
    <Button VerticalAlignment="Center" HorizontalAlignment="Right" Content="RIGHT" Background="White" Click="RightButton_OnClick" Name="BtnRight"/> 
</Grid> 

然后是调用了控制的XAML。

<Page 
x:Class="TestApp.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:TestApp" 
xmlns:controls="using:TestApp.Controls" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <controls:CarouselScrollViewer SegmentWidth="400"> 
     <controls:CarouselScrollViewer.ScrollViewerContent> 
      <StackPanel Orientation="Horizontal"> 
       <Image Source="Assets/cole_anne.png" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/icecream.JPG" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/jibby_hotdog.png" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/andy_courtney_norah.png" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/boating.JPG" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/dev.jpg" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/moir_crab.jpg" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
       <Image Source="Assets/MoirJudLindsayIlgaboating.jpg" Height="300" Width="400" Stretch="UniformToFill" Margin="5" /> 
      </StackPanel> 
     </controls:CarouselScrollViewer.ScrollViewerContent> 
    </controls:CarouselScrollViewer> 
</Grid> 

回答

0

ScrollViewer.HorizontalSnapPointsType property声明操纵行为的反应如何沿水平轴的捕捉点。而且,因为它是在备注声明,此属性适用于平移操作:

对于平移动作,经常有自然的停放场所。捕捉点提供了一种指示这些地点在哪里的方法。然后,当用户滑动时,操作结果倾向于使用如SnapPointsType值所表示的自然点使用行为。

更具体地说,该属性适用于触摸模式。参考Guidelines for panning的“摇摄行为”部分:

使用轻扫手势进行摇摄在触摸接触被解除时,会在交互中引入惯性行为。在惯性下,内容持续平移直到达到一定的距离阈值而没有用户的直接输入。使用捕捉点来修改这种惯性行为。

然而,在你的代码,您禁用了水平滚动和使用按钮滚动,所以捕捉点不会工作,设置HorizontalSnapPointsType属性将不会有任何效果。

相关问题