ListBox внутри ScrollViewer - PullRequest
       1

ListBox внутри ScrollViewer

3 голосов
/ 31 октября 2011

Понятия не имею, почему этот код работает нормально:

<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. В чем прикол?

Ответы [ 3 ]

9 голосов
/ 31 октября 2011

Следует избегать использования ScrollViewer для переноса ListBox, поскольку ScrollViewer уже есть внутри стиля ListBox по умолчанию.

3 голосов
/ 25 августа 2013

Просто измените шаблон для ListBox

<ListBox.Template>
  <ControlTemplate TargetType="ListBox">
    <Border>
      <ItemsPresenter />
    </Border>
  </ControlTemplate>
</ListBox.Template>
0 голосов
/ 31 октября 2011

Если вы правильно понимаете проблему, эта ссылка должна предоставить ответы на ваши вопросы.

http://forums.silverlight.net/t/11478.aspx/1

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...