2009-12-03 16 views
6

私はウィンドウのStackPanel内部ボーダー内部ScrollViewerの内部グリッドを持っています。ScrollViewerでビュー領域をスクロールするにはどうすればよいですか?

ScrollViewerのは、右側にスクロールバーを置きますが、それはないスクロールです。

どのようにして内容をスクロール可能にすることができますか?

alt text http://www.deviantsart.com/upload/1bl34e1.png

<Window x:Class="TestScroll234343.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="150" Width="300"> 
    <StackPanel> 
    <!--<StackPanel Height="150"> doesn't work either--> 
     <Border> 
      <ScrollViewer>    
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto"/> 
        </Grid.ColumnDefinitions> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="Auto"/> 
        </Grid.RowDefinitions> 

        <TextBlock Grid.Row="0" Grid.Column="0" Text="Row0"/> 
        <TextBlock Grid.Row="1" Grid.Column="0" Text="Row1"/> 
        <TextBlock Grid.Row="2" Grid.Column="0" Text="Row2"/> 
        <TextBlock Grid.Row="3" Grid.Column="0" Text="Row3"/> 
        <TextBlock Grid.Row="4" Grid.Column="0" Text="Row4"/> 
        <TextBlock Grid.Row="5" Grid.Column="0" Text="Row5"/> 
        <TextBlock Grid.Row="6" Grid.Column="0" Text="Row6"/> 
        <TextBlock Grid.Row="7" Grid.Column="0" Text="Row7"/> 
        <TextBlock Grid.Row="8" Grid.Column="0" Text="Row8"/> 
        <TextBlock Grid.Row="9" Grid.Column="0" Text="Row9"/> 
       </Grid> 
      </ScrollViewer> 
     </Border> 

    </StackPanel> 
</Window> 

答えて

7

あなたはScrollViewerの高さを設定する必要があります。

そうでない場合は、Borderは、それがどのような高さにしたいんScrollViewerを尋ねるとScrollViewerは、それがどのような高さにする必要がありBorderを要求します。

その他のオプション:

  • 変更DockPanelためStackPanelStackPanelの高さを設定
  • (それはWindow以上に成長しない)とScrollViewer
でそれに特異的に結合します

コード:

<StackPanel Height="140"> 
    <Border> 
     <ScrollViewer Height="{Binding RelativeSource={RelativeSource FindAncestor, 
        AncestorType={x:Type StackPanel}}, Path=Height}"> 
+0

ScrollViewerまたはBorderの高さを設定しますが、StackPanelまたはWindowは設定しないと動作します。とにかくScrollViewerに、コントロールの高さになるように指示しますか? –

+0

はい、編集された回答 –

+0

+1を参照してください。しかし、私は1つの問題にも気付きました。私の場合は、ListBoxでScrollViewを囲んでいます。マウススクロールは、ListBox内にないスクロールバーに沿ってのみスクロールできます。推測ListBoxは、ScrollViewには関係しません。コンテンツをスクロールできるようにするにはどうすればいいですか? (私のオリジナルのデザインでは、私はScrollViewerを指定しなかった) – HoKy22

関連する問題