开发者

W7P ListBox doesn't stay scrolled in the emulator

开发者 https://www.devze.com 2023-02-24 05:40 出处:网络
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 sh

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"/>开发者_JS百科; <!-- 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);
    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号