W7P ListBox 不会在模拟器中保持滚动状态

发布于 2024-10-31 18:30:30 字数 1059 浏览 0 评论 0原文

我在 Windows Phone 7 应用程序的 xaml 页面中有一个列表框。它一开始是空的,然后当从网络服务中检索到一些项目时,我会用它们填充它。到目前为止,一切正常 - 项目显示在列表中,一切看起来都很好。我遇到的问题是,当我尝试拖动列表滚动到底部(在模拟器中)时:我可以向下滚动,但是一旦释放鼠标按钮,列表就会弹回顶部,就好像我没有一样完全滚动了它。对于它为什么会这样表现有什么见解吗?

<Grid x:Name="ContentPanel" Grid.Row="2" Margin="0,0,0,0" Canvas.ZIndex="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/> <!-- EDIT: the problem was "Auto" here should have been "*" -->
    </Grid.RowDefinitions>

    <!-- removed other element for brevity -->

    <ListBox Name="InfoBoardListBox" Grid.Row="1" SelectionChanged="InfoBoardListBox_SelectionChanged"
              Margin="0,0,0,0" FontSize="26.667" />
</Grid>

以及填充列表的方法:

    foreach (InfoBoard entry in boards.Values) {
        item = new ListBoxItem();
        item.Content = entry.Name;
        item.Name = entry.Id.ToString(); //used to tell which entry was clicked
        InfoBoardListBox.Items.Add(item);
    }

I have a ListBox in a xaml page for a Windows Phone 7 app. It starts out empty, then I populate it with some items once they are retrieved from a web service. So far that all works fine - the items show up in the list and all seems fine. The problem I have is when I try to drag the list to scroll to the bottom (in the emulator): I can scroll down, but as soon as I release the mouse button the list springs back to the top as though I hadn't scrolled it at all. Any insights into why it would behave this way?

<Grid x:Name="ContentPanel" Grid.Row="2" Margin="0,0,0,0" Canvas.ZIndex="0">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/> <!-- EDIT: the problem was "Auto" here should have been "*" -->
    </Grid.RowDefinitions>

    <!-- removed other element for brevity -->

    <ListBox Name="InfoBoardListBox" Grid.Row="1" SelectionChanged="InfoBoardListBox_SelectionChanged"
              Margin="0,0,0,0" FontSize="26.667" />
</Grid>

And the method that populates the list:

    foreach (InfoBoard entry in boards.Values) {
        item = new ListBoxItem();
        item.Content = entry.Name;
        item.Name = entry.Id.ToString(); //used to tell which entry was clicked
        InfoBoardListBox.Items.Add(item);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第七度阳光i 2024-11-07 18:30:30

尝试将第二行的高度设置为*而不是Auto;我认为这与列表框认为它的大小与可用空间有关。

Try setting the Height of the second row to * instead of Auto; I think it's to do with the size that the ListBox thinks it is vs. the available space.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文