2011-12-24 10 views
-1

私の意図は簡単です。ユーザーがその特定のパネル内の多数のコントロールをスクロールできるソートパネルを作成します。そのパネル内のコントロールは、ボタン、画像、ラベルなどでも構いません。WP7 ScrollViewerは単に動作しません

Thing is ...私がScrollViewer Verticalを作成すると、スクロールされますが、スクロールバーがスクロールされますが、スクロールしたポイントには残りません。そして私がそれを水平にすると、それは私がそれが欲しい方法ですが、全くスクロールしません。

以下は私のコードです:よろしくお願いします!

<ScrollViewer Height="118" Name="scrollerButtons" Width="362" Canvas.Left="167" Canvas.Top="275" VerticalAlignment="Center"> 
     <StackPanel Height="97" Name="stackPanelButtons" Width="168" Orientation="Horizontal" Canvas.Left="162" Canvas.Top="43" VerticalAlignment="Center" HorizontalAlignment="Center"> 
       <Button Width="60" Height="60"> </Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
       <Button Width="60" Height="60"></Button> 
     </StackPanel> 
     </ScrollViewer> 

私はすべてをテストするためにたくさんのボタンを追加しました。どんな助力も高く評価されます。ありがとうございました。

答えて

2

StackPanelからHeight属性を削除します。内側のStackPanelに内容を切り捨てるよう強制しています。内側のStackPanelはScrollViewer(118)よりも小さいので(97)、ScrollViewerがスクロールすることはありません。 ScrollViewer は、の内容がScrollViewer自体よりも大きくなると予想しています。

+0

こんにちはジョーンズ。私はまさにそれをしました。まだ動作しません。 – Subby

+0

私はそれを修正しました!私はこれを追加:ScrollViewer.Horizo​​ntalScrollBarVisibility = "Auto" ScrollViewer.VerticalScrollBarVisibility = "Visible" – Subby

0

私がしたことは、スタックパネルを含むグリッド上のSizeChangedEventを聞いて、それに応じてScrollViewerの高さを調整したことです。ここでは、たとえば、画面サイズの半分にするだけです。それは完璧ではありませんが、それは動作します。

private void ContentPanel_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
     // Resize the scroll view if the stackpanel is bigger, additional 70 for app bar 
     if (e.NewSize.Height > 
       (System.Windows.Application.Current.Host.Content.ActualHeight - 70)) 
     { 
       ContentScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; 
       ContentScrollViewer.Height = System.Windows.Application.Current.Host.Content.ActualHeight/2; 
     } 
} 
関連する問題