Windows Phone ListBox无法滚动到底部

本文介绍如何解决ListBox无法滚动到底部的问题,关键在于通过将ListBox的Height属性绑定到其父容器的实际高度,确保ListBox知道自己的大小。通过在Grid中设置不同Row的高度属性,可以灵活调整各个组件的布局。示例代码展示了如何实现这一过程,包括使用DataTemplate为ListBox项设置样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.

ListBox无法滚动到底部,原因是Listbox它不知道自己有多高,所以需要添加以下代码。

<ListBox x:Name=”lstboxTasks” HorizontalContentAlignment=”Stretch” Height=”{Binding ElementName=LayoutRoot, Path=ActualHeight, Mode=OneWay}” ItemsSource=”{Binding Tasks}” Grid.Row=”1″>

注意红色部分,将LayoutRoot的实际高度与之绑定,告诉Listbox你有多高

2.

The key to scrolling is the Height value of the ScrollViewer or ListBox (with its built-in ScrollViewer). The Height should be set to the desired viewport size on the screen. You can set Height to an explicit number, but you can have Silverlight set it to the available height on the screen. Do this by putting the ScrollViewer or ListBox in a Grid row that has Height="*".

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
            <Grid.RowDefinitions>  
                <RowDefinition Height="Auto"/>  
                <RowDefinition Height="*"/>  
            </Grid.RowDefinitions>  
            <TextBox Grid.Row="0" Height="72" HorizontalAlignment="Left" Margin="0" Name="filter" Text="search" VerticalAlignment="Top" Width="458" LostFocus="filter_LostFocus" GotFocus="filter_GotFocus" Foreground="Gray" TextChanged="filter_TextChanged" />  
            <ListBox Grid.Row="1" HorizontalAlignment="Left" Margin="0,12,0,0" Name="people" VerticalAlignment="Top">  
                <ListBox.ItemTemplate>  
                    <DataTemplate>  
                        <TextBlock Text="{Binding BuiltName}" Style="{StaticResource PhoneTextLargeStyle}"/>  
                    </DataTemplate>  
                </ListBox.ItemTemplate>  
            </ListBox>  
        </Grid> 

Row 0 of the grid has Height="Auto" which means its height will expand to the total height of its contents. Row 1 of the grid has Height="*" which means it will be set to the remaining available height on the screen.

More information about Grid row height:  RowDefinition.Height Property

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值