2013-05-30 38 views
0

当使用Panorama控件时,非活动PanoramaItem中的元素响应点击事件。您可以使用以下XAML进行重现,该XAML仅从Windows Phone 8 SDK随附的Panorama应用程序解决方案模板中稍微修改而来。您可以看到第二个PanoramaItem中的项目是可点击的,即使PanoramaItem未处于活动状态。WP8:非活动PanoramaItem即使在非活动状态下也可点击

<phone:Panorama Title="my application"> 
    <phone:Panorama.Background> 
     <ImageBrush ImageSource="/PanoramaApp1;component/Assets/PanoramaBackground.png"/> 
    </phone:Panorama.Background> 

    <!--Panorama item one--> 
    <phone:PanoramaItem Header="first item"> 
     <!--Single line list with text wrapping--> 
     <phone:LongListSelector Margin="0,0,-22,0" ItemsSource="{Binding Items}"> 
      <phone:LongListSelector.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Margin="0,-6,0,12"> 
         <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeExtraLarge}"/> 
        </StackPanel> 
       </DataTemplate> 
      </phone:LongListSelector.ItemTemplate> 
     </phone:LongListSelector> 
    </phone:PanoramaItem> 

    <!--Panorama item two--> 
    <phone:PanoramaItem> 
     <!--Double line list with image placeholder and text wrapping using a floating header that scrolls with the content--> 
     <phone:LongListSelector Margin="0,-38,-22,2" ItemsSource="{Binding Items}"> 
      <phone:LongListSelector.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Horizontal" Margin="12,2,0,4" Height="105" Width="432" Tap="SecondItem_OnTap"> 
         <!--Replace rectangle with image--> 
         <Border BorderThickness="1" Width="99" Height="99" BorderBrush="#FFFFC700" Background="#FFFFC700"/> 
         <StackPanel Width="311" Margin="8,-7,0,0"> 
          <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Margin="10,0" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeLarge}" /> 
          <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="10,-2,10,0" Style="{StaticResource PhoneTextSubtleStyle}" /> 
         </StackPanel> 
        </StackPanel> 
       </DataTemplate> 
      </phone:LongListSelector.ItemTemplate> 
     </phone:LongListSelector> 
    </phone:PanoramaItem> 
</phone:Panorama> 

通知了“SecondItem_OnTap”点击事件处理程序挂钩在LongListSelector.ItemTemplate在第二PanoramaItem。

我在手机中没有预安装的每个应用程序中观察到此行为,换句话说,所有非Microsoft应用程序,包括Facebook和潘多拉等应用程序。有没有人有

  1. 首先,任何洞察力,为什么微软和非微软应用程序的行为是不同的;和
  2. 其次,有关如何解决此问题的建议?

回答

0

感谢您的答案!我用下面的解决了这个问题:

private void Panorama_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { 
    this.UpdateHitTestForPanoItems(this.Panorama.SelectedItem); 
} 

private void Panorama_OnLoaded(object sender, RoutedEventArgs e) { 
    this.UpdateHitTestForPanoItems(this.Panorama.SelectedItem ?? this.Panorama.Items.FirstOrDefault()); 
} 

private void UpdateHitTestForPanoItems(object selectedItem) { 
    foreach (PanoramaItem item in this.Panorama.Items) { 
     item.IsHitTestVisible = item == this.Panorama.SelectedItem; 
    } 
} 

当然,你需要分别实际挂钩的LoadedSelectionChanged事件到Panorama_OnLoadedPanorama_OnSelectionChanged方法。我也可以看到将它移到Behavior,你可以在你的应用程序的其他全景图中使用它。

0

这很麻烦,但您可以捕获Panorama的SelectionChanged事件并禁用可点击的元素。

0

是的,这是全景控制的一个众所周知的问题。我们在其中一个应用中通过在不活动的全景项目顶部创建透明叠加层来解决该问题。这种方法的缺点是,如果您在叠加层上开始侧滑动,手势将被忽略。对于我们最新的应用程序,我们简单地忽略此行为如果微软关心它,他们会解决它。至于为什么微软显然不在他们的应用中使用标准的手机控件。

相关问题