Setting focus to a PanoramaItem

2019-05-21 04:17发布

问题:

Is there a way to set focus to a PanoramaItem in Silverlight for Windows Phone 7?

I've tried:

piResults.Focus();

Where piResults is the name of a PanoramaItem. I've also tried to give focus to one of the controls in the PanoramaItem, but that didn't work either.

If this isn't clear, I'm trying to do the following: If you press a button on one PanoramaItem, you go to another.

回答1:

Have you tried setting the index of the PanoramaItem programatically, like -

piResults.DefaultItem = piResults.Items[_panorama_item_index_];

This technique is useful during Tombstoning. Here is the XAML for the Panorama control that I tried -

<!--Panorama item one-->
<controls:PanoramaItem Header="first item">
    <!--Double line list with text wrapping-->
    <Button x:Name="FirstButton" Content="Go to second item"
            Click="FirstButton_Click"/>

</controls:PanoramaItem>

<!--Panorama item two-->
<!--Use 'Orientation="Horizontal"' to enable a panel that lays out horizontally-->
<controls:PanoramaItem Header="second item">
    <!--Double line list with image placeholder and text wrapping-->
    <Button x:Name="SecondButton" Content="Go to first item"
            Click="SecondButton_Click"/>
</controls:PanoramaItem>

The events handlers are -

private void SecondButton_Click(object sender, RoutedEventArgs e)
{
  piResults.DefaultItem = piResults.Items[0];
}

private void FirstButton_Click(object sender, RoutedEventArgs e)
{
  piResults.DefaultItem = piResults.Items[1];
}

Hope this helps. indyfromoz