2011-08-03 5 views
1

データをロードするピボットアイテムに切り替えると、あるアイテムから別のアイテムに切り替えるときに吃音が発生しています。データ負荷を別のスレッドに分けて助けてくれましたが、まだまだパフォーマンスが悪いのですが....あなたには何か考えがあるかどうかは不思議でした....Windows Phone 7ピボットアイテムを切り替えるときに「吃音」を削除するには

ここはピボットアイテムです

<Grid x:Name="LayoutRoot" Background="Transparent"> 

    <!--Pivot control--> 
    <controls:Pivot Name="panCorals" Title="Corals" Foreground="#01487e" 
     SelectionChanged="panCorals_SelectionChanged"> 

     <controls:Pivot.Background> 
      <ImageBrush ImageSource="PivotBackground.png"/> 
     </controls:Pivot.Background> 

     <!--Search Corals--> 
     <controls:PivotItem Header="Search" Foreground="#01487e"> 

      <Grid> 

       <toolkit:PerformanceProgressBar Name="SearchCoralsProgressBar" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Width="466" 
         IsEnabled="{Binding IsSearchLoading}" IsIndeterminate="{Binding IsSearchLoading}" /> 

       <StackPanel> 
        <TextBox Name="txtSearchTerm" KeyDown="txtSearchTerm_KeyDown" /> 
        <ListBox Name="lbSearchCorals" Margin="0,0,-12,0" ItemsSource="{Binding SearchCorals}" 
         SelectionChanged="lbSearchCorals_SelectionChanged"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> 
            <Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" /> 
            <StackPanel Width="311"> 
             <TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/> 
             <TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
            </StackPanel> 
           </StackPanel> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
       </StackPanel> 
      </Grid> 

     </controls:PivotItem> 


     <!--Top Corals--> 
     <controls:PivotItem Header="Top" Foreground="#01487e" VerticalAlignment="Top" > 

      <Grid> 

       <toolkit:PerformanceProgressBar Name="TopCoralsProgressBar" HorizontalAlignment="Left" 
         VerticalAlignment="Top" Width="466" 
         IsEnabled="{Binding IsTopLoading}" IsIndeterminate="{Binding IsTopLoading}" /> 


       <ListBox Name="lbTopCorals" Margin="0,0,-12,0" ItemsSource="{Binding TopCorals}" SelectionChanged="lbTopCorals_SelectionChanged"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> 
           <Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" /> 
           <StackPanel Width="311"> 
            <TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/> 
            <TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
           </StackPanel> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 

       <StackPanel Margin="10,50,0,0" Orientation="Horizontal"> 
        <TextBlock x:Name="tbProgress"/> 
       </StackPanel> 

      </Grid> 

     </controls:PivotItem> 

     <!--New Corals--> 
     <controls:PivotItem Header="New"> 
      <Grid> 

       <toolkit:PerformanceProgressBar Name="NewCoralsProgressBar" HorizontalAlignment="Left" 
          VerticalAlignment="Top" Width="466" 
          IsEnabled="{Binding IsNewLoading}" IsIndeterminate="{Binding IsNewLoading}" /> 

       <ListBox Name="lbNewCorals" Margin="0,0,-12,0" ItemsSource="{Binding NewCorals}" SelectionChanged="lbNewCorals_SelectionChanged"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Orientation="Horizontal" Margin="0,0,0,17"> 
           <Image Source="{Binding MainImageURI}" Height="100" Width="100" Margin="12,0,9,0" /> 
           <StackPanel Width="311"> 
            <TextBlock Text="{Binding CommonName}" Foreground="#112d42" TextWrapping="NoWrap" Style="{StaticResource PhoneTextTitle2Style}"/> 
            <TextBlock Text="{Binding ScientificName}" Foreground="#112d42" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
           </StackPanel> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 

      </Grid> 
     </controls:PivotItem> 


    </controls:Pivot> 
</Grid> 

そして背後にあるコード...たまたま

private void panCorals_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     switch (panCorals.SelectedIndex) 
     { 
      case 0:  //search corals 

       break; 
      case 1:   //top corals 
       if (!App.vmCoral.IsTopDataLoaded) 
       { 
        App.vmCoral.IsTopLoading = true; 
        if (App.HasConnectivity) 
        { 
         //get corals from web 
         bw.DoWork += new DoWorkEventHandler(bw_DoWorkTopCoralsWeb); 

         if (bw.IsBusy != true) 
         { 
          bw.RunWorkerAsync(); 
         } 

        } 
        else 
        { 
         //get saved corals from device 
         bw.DoWork += new DoWorkEventHandler(bw_DoWorkTopCoralsSaved); 

         if (bw.IsBusy != true) 
         { 
          bw.RunWorkerAsync(); 
         } 
        } 
       } 
       break; 
      case 2:   //new corals 

       if (!App.vmCoral.IsNewDataLoaded) 
       { 
        App.vmCoral.IsNewLoading = true; 
        if (App.HasConnectivity) 
        { 
         //get corals from web 
         bw.DoWork += new DoWorkEventHandler(bw_DoWorkNewCoralsWeb); 

         if (bw.IsBusy != true) 
         { 
          bw.RunWorkerAsync(); 
         } 

        } 
        else 
        { 
         //get saved corals from device 
         bw.DoWork += new DoWorkEventHandler(bw_DoWorkNewCoralsSaved); 

         if (bw.IsBusy != true) 
         { 
          bw.RunWorkerAsync(); 
         } 
        } 
       } 

       break; 
      default: 

       break; 
     } 

    } 

答えて

5

あなた自身が投稿したコードに特に問題はありません。あなたのバックグラウンドワーカースレッドがピボットアイテム間で切り替えている間にあなたのバックグラウンドワーカースレッドが完了していて、リストがバインドされているオブザーバブルコレクションが更新されている可能性があります。また、あなたのリストには、ウェブ上のURLにバインドしてイメージをダウンロードする必要がある場合、perf問題が発生するイメージが含まれています。

  1. は、あなたのリストが長い場合は、仮想化スタックパネルを使用していることを確認します(これがデフォルトですが、あなたはどこにでもそれを変更していないことを確認してください):

    があるカップルの事を確認することです。

  2. はSLツールキットからLongListSelectorコントロールの使用を検討し、それはあなたがウェブのURL(http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx)にあなたのイメージを結合している場合は、低プロフィール画像ローダをチェックアウトするデフォルトのリストボックス
  3. より良いUIとデータ仮想化をサポートしています。
  4. App.xaml.cs.xの "EnableRedrawRegions"デバッグインジケータを有効にします。ピボットアイテムを切り替えるときに領域が再描画される原因がないことを確認します(画面の各セクションが非常に速く点滅していることが示されます)。可能であれば、BitMapCacheの使用を検討してください。
  5. もしあなたの非同期プロセスが長いリストをダウンロードしているのであれば、バックグラウンドスレッド上でリストを分割し、それぞれを小さなスレッドでUIスレッドにディスパッチすることを検討してください。
+0

LongListSelectorのアイデアについて言及したいと思います。これは本当に助けになるものと思われます。 – Jarrette

2

一つの一般的な状況は、あなたが完全に別のスレッドでデータをロードするものの、ロードが完了した後、多くのUIの仕事のアイテムを結合するためにはあるということですListBoxに追加します。

私は以前、ネット上で発見した1つの解決策(実際にはリンクのトラックを失った)は、あなたのObservableCollection(あなたのケースSearchCorals)に1つずつ、遅れてアイテムを追加することです)。 (一括して追加するのではなく)。

これを行うには、データソースをメモリに保存し、DispatcherTimerを使用して50msごとに実行し、項目をSearchCoralsに1つずつ追加します。

これは私の問題を解決しました。

+0

検索ピボットから「トップ」ピボットアイテムに切り替えると吃音が発生します。アニメーションが一時停止し、トップページが読み込まれた後、読み込みアニメーションが取得された後、データが読み込まれます。吃音が終わったらもう数秒待たなければならない。 – Jarrette

関連する問題