1

私のWindows Phone 8アプリケーションでは、結果をリストボックスに表示しています。毎回、リストに 20 項目しか表示されません。

次の 20 項目を表示するには、[次へ] ボタンを追加し、古い項目を表示するには、[前へ] ボタンを追加します。

以下は私のコードブロックです。これでは、別のリスト ボックス内のリスト ボックスを使用して、リストの後にボタンを表示しています。しかし、リストはスクロールしていません。

<Grid x:Name="ContentPanel" Grid.Row="3" Background="White" Margin="0,-3,0,0">
        <ListBox x:Name="outerList">
            <ScrollViewer Margin="0,0,0,0">
                <ListBox x:Name="companiesList"  SelectionChanged="companiesList_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Auto">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid x:Name="listItem">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="50"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="10"/>
                                </Grid.RowDefinitions>

                                <StackPanel x:Name="namePanel" Grid.Row="0" Orientation="Horizontal" Margin="5,0,0,5" Height="50">
                                    <TextBlock x:Name="nameTextBlock" Text="{Binding CompanyName}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="28" MaxHeight="40" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460" FontWeight="Bold"/>
                                </StackPanel>

                                <StackPanel x:Name="addressPanel" Grid.Row="1" Orientation="Horizontal" Margin="5,0,0,5" Height="30">
                                    <TextBlock x:Name="addressTextBlock"  Text="{Binding Address}" Foreground="#FF1F1F1F" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460"/>
                                </StackPanel>

                                <StackPanel x:Name="phonePanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,0" Height="30">
                                    <Image x:Name="phone" Stretch="Uniform" Margin="0,0,0,0" Height="25" Source="Images/list_phone.png"  />
                                    <TextBlock x:Name="phoneTextBlock" Text="{Binding Phone1}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Width="460"/>
                                </StackPanel>

                                <Image  x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png"  />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </ScrollViewer>
            <StackPanel Height="50" Orientation="Horizontal">
                <Button Content="Previous" Height="70" HorizontalAlignment="Left" Margin="-5,1,0,0" Name="prevbutton" VerticalAlignment="Center" Width="160" Foreground="#FF501F6E">
                    <Button.Background>
                        <ImageBrush Stretch="Fill" ImageSource="Images/blank_button_nav.png"/>
                    </Button.Background>
                </Button>
                <Button Content="Next" Height="70" HorizontalAlignment="Left" Margin="170,1,0,0" Name="nextbutton" VerticalAlignment="Center" Width="160" Foreground="#FF501F6E">
                    <Button.Background>
                        <ImageBrush Stretch="Fill" ImageSource="Images/blank_button_nav.png"/>
                    </Button.Background>
                </Button>
            </StackPanel>
        </ListBox>
    </Grid>

スクロール可能なリスト ボックスにボタンを追加する方法を教えてください。

4

1 に答える 1

0

ListBox を別の ListBox 内に配置できます。ここで、項目は結果の ListBox とボタンです。たとえば、次のようになります。

<Grid x:Name="ContentPanel" Grid.Row="3" Background="White" Margin="0,-3,0,0">
    <ListBox x:Name="outerList">
            <ListBox x:Name="companiesList" Height="{Binding ActualHeight, ElementName=ContentPanel}"  SelectionChanged="companiesList_SelectionChanged" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid x:Name="listItem">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="50"/>
                                <RowDefinition Height="30"/>
                                <RowDefinition Height="30"/>
                                <RowDefinition Height="10"/>
                            </Grid.RowDefinitions>

                            <StackPanel x:Name="namePanel" Grid.Row="0" Orientation="Horizontal" Margin="5,0,0,5" Height="50">
                                <TextBlock x:Name="nameTextBlock" Text="{Binding CompanyName}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="28" MaxHeight="40" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460" FontWeight="Bold"/>
                            </StackPanel>

                            <StackPanel x:Name="addressPanel" Grid.Row="1" Orientation="Horizontal" Margin="5,0,0,5" Height="30">
                                <TextBlock x:Name="addressTextBlock"  Text="{Binding Address}" Foreground="#FF1F1F1F" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Margin="0,0,0,0" Width="460"/>
                            </StackPanel>

                            <StackPanel x:Name="phonePanel" Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,0" Height="30">
                                <Image x:Name="phone" Stretch="Uniform" Margin="0,0,0,0" Height="25" Source="Images/list_phone.png"  />
                                <TextBlock x:Name="phoneTextBlock" Text="{Binding Phone1}" Foreground="#FF501F6E" Style="{StaticResource PhoneTextNormalStyle}" HorizontalAlignment="Left" FontSize="20" MaxHeight="30" TextTrimming="WordEllipsis" Width="460"/>
                            </StackPanel>

                            <Image  x:Name="line" Grid.Row="3" Width="460" HorizontalAlignment="Center" Source="Images/separator.png"  />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        <StackPanel Height="50" Orientation="Horizontal">
            <Button Content="Previous" Height="70" HorizontalAlignment="Left" Margin="-5,1,0,0" Name="prevbutton" VerticalAlignment="Center" Width="160" Foreground="#FF501F6E">
                <Button.Background>
                    <ImageBrush Stretch="Fill" ImageSource="Images/blank_button_nav.png"/>
                </Button.Background>
            </Button>
            <Button Content="Next" Height="70" HorizontalAlignment="Left" Margin="170,1,0,0" Name="nextbutton" VerticalAlignment="Center" Width="160" Foreground="#FF501F6E">
                <Button.Background>
                    <ImageBrush Stretch="Fill" ImageSource="Images/blank_button_nav.png"/>
                </Button.Background>
            </Button>
        </StackPanel>
    </ListBox>
</Grid>

ボタンがタップされると、内側の ListBox の内容を変更できます。

于 2013-07-02T07:19:09.967 に答える