简体   繁体   中英

wp7 scrollviewer Listbox not working

 <controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
            <ScrollViewer HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Stretch">
                <ListBox x:Name="monthlyItemListBox"  ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
                                <TextBlock Text="{Binding Id}"  FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Name}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Surname}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Age}" FontSize="24" />
                                <TextBlock Text="    " FontSize="24" />
                                <TextBlock Text="{Binding Status}" FontSize="24" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </ScrollViewer>
        </Grid>
    </controls:PanoramaItem>

I tried my list with 50 members but ı cant view the scrollviewer what might cause the problem? Thanks I see some answers here and I tried but not working(Changing height ... etc) thanks.

ListBox already has a ScrollViewer , and the two controls will fight over your manipulations.

Remove the outer ScrollViewer , or set ScrollViewer.VerticalScrollBarVisibility="Disabled" on your ListBox to disable scrolling.

And not sure if you're using those TextBlocks for Margin , but you should either set the Margin directly, or use ColumnDefinitions and a Grid .

<controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
                <ListBox x:Name="monthlyItemListBox" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="*" />
                              </Grid.ColumnDefinitions>

                                <TextBlock Text="{Binding Id}" Grid.Column="0" FontSize="24" />
                                <TextBlock Text="{Binding Name}" Grid.Column="1" FontSize="24" />
                                <TextBlock Text="{Binding Surname}" Grid.Column="2" FontSize="24" />
                                <TextBlock Text="{Binding Age}" Grid.Column="3" FontSize="24" />
                                <TextBlock Text="{Binding Status}" Grid.Column="4" FontSize="24" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </Grid>
    </controls:PanoramaItem>

or

<controls:PanoramaItem Header="Aylık" Foreground="White">
        <Grid x:Name="monthlyPanaromaGrid" >
            <Grid.Resources>
                <Style TargetType="ListBoxItem" x:Key="ListItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </Grid.Resources>
                <ListBox x:Name="monthlyItemListBox" HorizontalAlignment="Stretch"  ScrollViewer.VerticalScrollBarVisibility="Auto" >
                    <ListBox.ItemTemplate >
                        <DataTemplate>
                            <Grid HorizontalAlignment="Stretch">
                              <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="Auto" />
                              </Grid.ColumnDefinitions>

                                <TextBlock Text="{Binding Id}" Grid.Column="0" FontSize="24" />
                                <TextBlock Text="{Binding Name}" Margin="48,0,0,0" Grid.Column="1" FontSize="24" />
                                <TextBlock Text="{Binding Surname}" Margin="48,0,0,0" Grid.Column="2" FontSize="24" />
                                <TextBlock Text="{Binding Age}" Margin="48,0,0,0" Grid.Column="3" FontSize="24" />
                                <TextBlock Text="{Binding Status}" Margin="48,0,0,0" Grid.Column="4" FontSize="24" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
        </Grid>
    </controls:PanoramaItem>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM