2011-10-30 43 views
3

我不知道爲什麼這個代碼工作正常:列表框裏面的ScrollViewer

<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> 
    <StackPanel> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
     <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
    </StackPanel> 
</ScrollViewer> 

,這並不:

<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"> 
    <ListBox Width="480" ItemsSource="{Binding ViewModel_ObservableCollection_Property_With_15_Items}"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid Height="85"> 
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" /> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</ScrollViewer> 

一個ListBox的版本是無法顯示在ScrollViewer中的所有項目。有什麼竅門?

回答

9

應避免使用的ScrollViewer包裝一個列表框前面已經有默認的列表框樣式裏面的ScrollViewer。

+4

歐,是的。我真笨。我沒有意識到這一點。謝謝。 –

3

只需更改模板列表框

<ListBox.Template> 
    <ControlTemplate TargetType="ListBox"> 
    <Border> 
     <ItemsPresenter /> 
    </Border> 
    </ControlTemplate> 
</ListBox.Template>