2012-02-18 103 views
10

我剛剛開始在WinPhone開發中,無法弄清楚如何設置垂直滾動。例如我已經開始了一個新的支點應用程序,而這個代碼允許用戶滾動和d自己看到所有條目:Windows Phone如何垂直滾動

<controls:PivotItem Header="Login"> 
    <!--Double line list with text wrapping--> 
    <ListBox x:Name="FirstListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Margin="0,0,0,17" Width="432" Height="78"> 
        <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
        <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</controls:PivotItem> 

現在時,添加自己的支點項目,與一個StackPanel在任何時候都可以在屏幕上看到更多的項目,它不會允許我滾動查看全部內容。我在這裏錯過了什麼?

謝謝。

回答

23

通過StackPanel添加ScrollViewer,它將使它可以滾動。

6

您提供的示例代碼中的ListBox具有內置滾動功能。但是,如果您沒有使用已經具有此滾動功能的東西,則必須添加ScrollViewer

<controls:PivotItem Header="Example"> 
    <ScrollViewer Margin="12,0,12,0"> 
     <StackPanel> 
      <TextBlock Text="Example1" FontSize="150" /> 
      <TextBlock Text="Example2" FontSize="150" /> 
     </StackPanel> 
    </ScrollViewer> 
</controls:PivotItem> 
1

在樞軸控件中,如果內容溢出垂直頁面,則應該有可用的默認「垂直」滾動。

我有一個類似的控件與列表框綁定到屬性。擁有「列表」應自動允許您滾動。

不要在堆疊面板上添加滾動查看器,因爲它會爲每個不需要的列表項目啓用滾動。

<controls:PivotItem Header="all authors" Foreground="#FF0C388A"> 
      <Grid> 
       <ListBox Margin="0,0,-12,0" ItemsSource="{Binding AllAuthorsList}" Foreground="#FF0C388A"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
           <StackPanel Margin="0,0,0,17" Width="432" Height="Auto"> 
            <TextBlock Tap="TextBlockAuthor_Tap" Text="{Binding}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" Foreground="#FF0C388A"/> 
           </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
      </Grid> 
     </controls:PivotItem>