2009-08-16 21 views
2

以下のスクロールビューアは機能しません。私はこのサイトとそれ以降で見つけられたすべてを試しました:スクロールビューアをグリッドに埋め込み、グリッドにScrollViewerの子を埋め込み、StackPanelにStackPanelを埋め込み、スクロールビューアの高さを設定/バインドしました。 ...誰が私に正気に戻る方法を示していますか?ScrollViewerがスクロールしない

マインド、以下のXAMLは、ウィンドウの構造を示しています。私はすべてのデータを削除しました。

<Window> 
    <Window.Resources> 
     <DataTemplate x:Key="ColoringLabels"> 
     </DataTemplate> 
    </Window.Resources> 
    <DockPanel> 
     <StatusBar DockPanel.Dock="Top"> 
      <StatusBarItem> 
      </StatusBarItem> 
     </StatusBar> 
     <StackPanel Orientation="Vertical"> 
      <TextBox/> 
      <Button>Hello World!</Button> 
      <ScrollViewer> 
       <StackPanel Orientation="Vertical"> 
        <Label>Hola Mundo!</Label> 
        <ListBox ItemsSource="{Binding}"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <ListBox ItemsSource="{StaticResource ColoringLabels}"/> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
        <ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/> 
       </StackPanel> 
      </ScrollViewer> 
      <TextBlock/> 
     </StackPanel> 
    </DockPanel> 
</Window> 

EDIT:

私はにXAMLを変更することによってそれを解決:それが今取り組んでいるのはなぜ

<Window> 
    <Window.Resources> 
     <DataTemplate x:Key="ColoringLabels"> 
     </DataTemplate> 
    </Window.Resources> 
    <DockPanel> 
     <StatusBar DockPanel.Dock="Top"> 
      <StatusBarItem> 
      </StatusBarItem> 
     </StatusBar> 
     <ScrollViewer> 
      <StackPanel Orientation="Vertical"> 
       <TextBox /> 
       <Button>Hello World!</Button> 
        <StackPanel Orientation="Vertical"> 
         <Label>Hola Mundo!</Label> 
         <ListBox ItemsSource="{Binding}"> 
          <ListBox.ItemTemplate> 
           <DataTemplate> 
            <ListBox ItemsSource="{StaticResource ColoringLabels}"/> 
           </DataTemplate> 
          </ListBox.ItemTemplate> 
         </ListBox> 
         <ListBox Source="{Binding}"ItemTemplate="{StaticResource ColoringLabels}"/> 
        </StackPanel> 
       <TextBlock/> 
      </StackPanel> 
     </ScrollViewer> 
    </DockPanel> 
</Window> 

???おそらくScrollViewerがDockPanelのLastChildの位置を埋めるようになったからでしょうか?

+0

私は今同じ問題を抱えています。私はあなたの解決策を試しました。しかし、私の仕事はなぜうまくいかないのですか?スクロールビューアでリストボックスを使用すると、それは台無しになります。 –

答えて

4

試みをスクロールしているあなたのケースでは、それのサイズよりも大きいですときScrollViewerのがスクロールし、ScrollViewerの中であなたのリストボックスまたはのStackPanelに高さを与えるようにしてくださいこの

<Window x:Class="WpfApplication7.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="308" Width="527"> 
    <Window.Resources> 
     <DataTemplate x:Key="ColoringLabels"> 
     </DataTemplate> 
    </Window.Resources> 
    <DockPanel LastChildFill="True"> 
     <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch"> 
      <StatusBar> 
       <StatusBarItem> 
       </StatusBarItem> 
      </StatusBar> 
      <TextBox/> 
      <Button>Hello World!</Button> 
     </StackPanel> 
     <ScrollViewer> 
      <StackPanel Orientation="Vertical" > 
       <Label>Hola Mundo!</Label> 
       <ListBox ItemsSource="{Binding}"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <ListBox /> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
       <ListBox /> 
      </StackPanel> 
     </ScrollViewer> 
     <TextBlock/> 
    </DockPanel> 

</Window> 

EDIT
あなたの新しいコードはScrollViewerのサイズは(それが画面の空き部分を埋めるのです)今固定されており、それはコンテンツが成長しているのですとき、それは窓の外に成長していないだけでbecouse取り組んでいます。.. 。

+0

あなたがこれに入れているすべての仕事をありがとう!私は以前の提案に従って、scrollviewerの下の最初のスタックパネルに高さを加え(何も起こらなかった)、リストボックスに高さを与えました。それはうまくいったが、望みの効果を生み出さなかった。私はScrollviewerを上位階層に配置し、それは私が探していたものを生成しました。 – Dabblernl

+0

あなたはウェルカムです、私は投稿を編集し、あなたの最後のquestinの答えを見つける。 –

1

それはコンテンツがあなたがリストボックスに項目を追加する場合、リストボックスの高さが成長していないとリストボックスが

関連する問題