WP7 - 如何在一个页面中添加多个列表框。 [英] WP7 - How to add multiple list box in one page.

查看:41
本文介绍了WP7 - 如何在一个页面中添加多个列表框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows Phone 7应用程序中,我必须添加多个列表框。我的要求是用户可以滚动页面查看所有项目。但我不知道如何在一个页面中添加多个列表框。我试过这样的。

In my windows phone 7 app i have to add more than one list box. My requirement is user can scroll the page to see all the items. But i don't know how to add multiple list box in one page. I have try like this.

 <Grid x:Name="testUIContainer" Grid.Row="1" Margin="2,0,2,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ScrollViewer VerticalScrollBarVisibility="Visible" 
                  MaxWidth="477">
                <ScrollViewer.Content>
                    <StackPanel Margin="0, 30, 0, 0 ">
                        <Rectangle  Height="50" Margin="0,0,0,0" Name="Header" Stroke="Black" StrokeThickness="1" Width="480" Grid.ColumnSpan="2" Fill="#FF01A1DB" />

                        <ListBox Grid.Row="0" ItemsSource="{Binding StudentDetails,Mode=TwoWay}" Margin="0,0,0,0" Name="listBox1" Width="476" BorderBrush="#00410D0D">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border BorderBrush="Gray" Padding="5" BorderThickness="1">
                                        <StackPanel Orientation="Horizontal" >
                                            <Border BorderBrush="Wheat" BorderThickness="1">
                                                <Image  Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
                                            </Border>
                                            <TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22"  />
                                            <TextBlock Text="{Binding LastName}" Name="lastName" Width="200" Foreground="White" Margin="-200,50,0,0" FontWeight="SemiBold" FontSize="22"  />
                                            <TextBlock Text="{Binding Age}" Name="age" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22"  />

                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>

                        <ListBox Grid.Row="1" ItemsSource="{Binding StudentDetails,Mode=TwoWay}" HorizontalAlignment="Left" Margin="0,0,0,0" Name="listBoxes1" Width="476" BorderBrush="#00410D0D">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Border BorderBrush="Gray" Padding="5" BorderThickness="1">
                                        <StackPanel Orientation="Horizontal" >
                                            <Border BorderBrush="Wheat" BorderThickness="1">
                                                <Image  Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
                                            </Border>
                                            <TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22"  />
                                            <TextBlock Text="{Binding LastName}" Name="lastName" Width="200" Foreground="White" Margin="-200,50,0,0" FontWeight="SemiBold" FontSize="22"  />
                                            <TextBlock Text="{Binding Age}" Name="age" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22"  />

                                        </StackPanel>
                                    </Border>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>

                    </StackPanel>
                </ScrollViewer.Content>
            </ScrollViewer>
        </Grid>
    </Grid>


  

但是在这里我看不到第二个列表框项目。这仅是示例。我必须在页面中添加4到5个列表框。请让我知道如何在一个页面中添加多个列表框。或者还有其他选项可以显示所有项目列表。 

  

But here i can not see the second list box items. This is example only. I have to add 4 to 5 list box in a page. Please let me know how to add multiple list box in one page. Or there is any other option to show all the list of items. 

提前致谢.. 

Thanks in advance.. 

推荐答案

在页面中包含多个列表框是不好的做法,除非页面是数据透视图或全景图。

Having multiple listboxes in a page is bad practice, unless the page is a pivot or a panorama.

您还将列表框放在滚动查看器中,这也是不好的做法。您应该熟悉列表框控件。

You are also putting listboxes inside scrollviewers, which, again, is bad practice. You should familiarize yourself with the listbox control.

我也没有看到需要2个列表框。只需在一个列表中填充所有Student对象,就可以一次显示所有这些对象。

I also fail to see the need of having 2 listboxes. Simply populate all the Student objects in a single list and they can be displayed all at once.


这篇关于WP7 - 如何在一个页面中添加多个列表框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆