0
votes

I'm building a WP7 application using the Panorama control. I'm fairly new to WP7 so I might be missing something simple. My Panorama control is bound to ViewModel and PanoramaItems are added at runtime when a property of that ViewModel is populated with data via web service request. I'd like to have a section at the top of each PanoramaItem that holds a refresh button etc.

I'm able to add an item to the top of the ListBox using a Style but I would like to have that item scrolled off the top until a user pulls it down. Is there a way to set a default scroll position in the Style or in Template? I've read a few example of scrolling to a particular item once there is data using listBox.ScrollToItem, but that didn't work in my test application, or getting a handle on the ScrollViewer and using ScrollToVerticalOffset.

<phone:PhoneApplicationPage.Resources>
    <Style x:Key="StoryStyle" TargetType="ListBox">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBox">
                    <ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
                        <StackPanel>
                            <Button Content="Refresh"></Button>
                            <ItemsPresenter/>
                        </StackPanel>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>

<Grid x:Name="LayoutRoot" Background="Transparent">
    <controls:Panorama ItemsSource="{Binding Programs}" x:Name="AllPrograms">
        <controls:Panorama.Title>
            <TextBlock></TextBlock>
        </controls:Panorama.Title>
        <controls:Panorama.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Title}" />
            </DataTemplate>
        </controls:Panorama.HeaderTemplate>
        <controls:Panorama.ItemTemplate>
            <DataTemplate>
                <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Stories}" Style="{StaticResource StoryStyle}">

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17" Width="432" Height="80">
                                <TextBlock Text="{Binding SensibleTitle}" TextWrapping="Wrap" />
                                <TextBlock><Run Text="{Binding Duration, StringFormat='hh\\:mm\\:ss'}"></Run><Run Text=", "/><Run Text="{Binding DisplayDate, StringFormat='MMMM dd, yyyy'}"/></TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            </DataTemplate>
        </controls:Panorama.ItemTemplate>
    </controls:Panorama>
</Grid>
1

1 Answers

0
votes

Try changing SelectedIndex for ListBox.