2015-07-11 85 views
0

我在我的XAML中有一个ScrollViewer。我想水平滚动到右侧的末端,以便用户可以看到ScrollViewer中的所有控件。用ScrollViewer XAML水平滚动到最后wp8

这里是我的代码:

<ScrollViewer x:Name="ScrollFilter" HorizontalScrollBarVisibility="Auto" HorizontalScrollMode="Enabled"> 
       <StackPanel HorizontalAlignment="Left"> 
        <Rectangle x:Name="RecAntiqueFilter" Fill="Red" Height="100" Width="100" DoubleTapped="RecAntiqueFilter_DoubleTapped" Tapped="RecAntiqueFilter_Tapped"/> 
        <Rectangle x:Name="RecBlurFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-200,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHSTFilter" Fill="Blue" Height="100" Width="100" Margin="0,-100,-400,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecBFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-600,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHFilter" Fill="Blue" Height="100" Width="100" Margin="0,-100,-800,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-1000,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHcFilter" Fill="Yellow" Height="100" Width="100" Margin="0,-100,-1200,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecFake" Fill="Transparent" Height="100" Width="400" Margin="0,-100,-1400,0"/> 

       </StackPanel> 
      </ScrollViewer> 

怎么办呢?

回答

1

对于水平滚动,您必须使用堆叠面板方向属性,更新代码如下。

<ScrollViewer x:Name="ScrollFilter" HorizontalScrollBarVisibility="Auto" HorizontalScrollMode="Enabled"> 
       <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> 
        <Rectangle x:Name="RecAntiqueFilter" Fill="Red" Height="100" Width="100" DoubleTapped="RecAntiqueFilter_DoubleTapped" Tapped="RecAntiqueFilter_Tapped"/> 
        <Rectangle x:Name="RecBlurFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-200,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHSTFilter" Fill="Blue" Height="100" Width="100" Margin="0,-100,-400,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecBFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-600,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHFilter" Fill="Blue" Height="100" Width="100" Margin="0,-100,-800,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecFilter" Fill="Green" Height="100" Width="100" Margin="0,-100,-1000,0" Tapped="RecBlurFilter_Tapped"/> 
        <Rectangle x:Name="RecHcFilter" Fill="Yellow" Height="100" Width="100" Margin="0,-100,-1200,0" Tapped="RecHSTFilter_Tapped"/> 
        <Rectangle x:Name="RecFake" Fill="Transparent" Height="100" Width="400" Margin="0,-100,-1400,0"/> 
</StackPanel> 
</ScrollViewer> 
+0

哇!你刚刚救了我的一天。感谢您的帮助。自昨晚以来,我试图这样做。顺便说一句,有无论如何我可以修改水平滚动条?例如,更改滚动条的颜色或更改它的宽度? –

+0

不客气;)对于更改样式,您可以查看MSDN页面; https://msdn.microsoft.com/en-us/library/cc278076(v=vs.95).aspx ...我以前没有尝试过。 –