2012-05-07 30 views
3

我有一個Panorama控件,它有一個ExpanderView項目(來自Silverlight工具包)。 我的客戶希望此頁面可以自定義。這就是爲什麼我創建了3級綁定: PanoramaItems,ExpanderView標題和ExpanderView內容。 設置Panorama控件的itemssource時出現問題。大約需要5秒鐘來顯示項目。使用ExpanderView和綁定時緩慢頁面加載(Windows Phone 7)

任何想法如何解決這個問題?

C#代碼:

private void panorama_Loaded(object sender, RoutedEventArgs e) 
{ 
     this.DataContext = App.Products; 
} 

XAML代碼:

<controls:Panorama Loaded="panorama_Loaded" x:Name="panorama" ItemsSource="{Binding}"> 
     <controls:Panorama.ItemTemplate> 
      <DataTemplate> 
       <ListBox ItemsSource="{Binding Sub_Products}" > 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <toolkit:ExpanderView Header="{Binding}" Expander="{Binding}" ItemsSource="{Binding Sub_Sub_Products}"> 
           <toolkit:ExpanderView.ExpanderTemplate> 
            <DataTemplate> 
             <StackPanel Orientation="Horizontal"> 
              <Image VerticalAlignment="Center" Source="Images/List.png" Width="25" /> 
              <TextBlock Text="{Binding Title}" /> 
             </StackPanel> 
            </DataTemplate> 
           </toolkit:ExpanderView.ExpanderTemplate> 
           <toolkit:ExpanderView.ItemTemplate> 
            <DataTemplate> 
             <Grid Margin="-30,0,0,0" Background="White" Width="450" Tap="Grid_Tap" > 
              <Grid.ColumnDefinitions> 
               <ColumnDefinition Width="Auto" /> 
               <ColumnDefinition Width="*" /> 
              </Grid.ColumnDefinitions> 
              <Grid.RowDefinitions> 
               <RowDefinition Height="Auto" /> 
               <RowDefinition Height="*" /> 
              </Grid.RowDefinitions> 
              <Image Grid.Row="0" Source="{Binding ImageSource}" /> 
              <StackPanel VerticalAlignment="Top" Grid.Column="1"> 
               <TextBlock Text="{Binding Title}" /> 
               <TextBlock Text="{Binding Description}" /> 
               <Grid> 
                <Grid.ColumnDefinitions> 
                 <ColumnDefinition Width="Auto" /> 
                 <ColumnDefinition Width="*" /> 
                </Grid.ColumnDefinitions> 
                </Grid> 
               <TextBlock Margin="0,12,32,0" Grid.Row="1" Text="Learn more" /> 
              </StackPanel> 
             </Grid> 
            </DataTemplate> 
           </toolkit:ExpanderView.ItemTemplate> 
          </toolkit:ExpanderView> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
      </DataTemplate> 
     </controls:Panorama.ItemTemplate> 
    </controls:Panorama> 
+1

顯示一些代碼。另外,您加載了多少數據(多少個全景項目,多少標題以及多少內容)?指導方針說,出於性能原因,你應該少於5個全景物品。 – Robaticus

+0

我有4個全景物品,大概有3-6個expanderview頭,每個都有3個expanderview內容。代碼很長,生病嘗試減少線路並在此分享。謝謝 – Ateik

回答

1

你可以嘗試,以摺疊該是關閉屏幕,只設置能見度可見對需求的全景物品。這應該至少減少可見樹的大小。

查找緩慢部分的好方法是在Visual Studio中使用分析器。你會發現一幀非常慢(在你的情況下它的渲染時間爲5秒)。然後深入該框架的視覺樹中,看看哪些元素需要很長時間才能渲染並嘗試優化這些元素。

+0

嗨,我不會忽視你的答案。我沒有時間去嘗試,參與了另一個項目。如果它有效,會給你點數:) – Ateik

0

刪除xaml中的ExpanderView ItemsSource綁定,並在代碼中處理Expander時綁定到它。只需將其保留爲ItemsSource="{Binding}"即可。這樣,當用戶點擊擴展器時,您將動態構建視覺樹。

事件處理程序如下所示。 我假設產品是您的App.Products列表中的類型。還要確保你在xaml中爲擴展器連接事件。

private void ExpanderView_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e) 
     { 
      var expander = sender as ExpanderView; 
      expander.ItemsSource = (expander.DataContext as Product).Sub_Sub_Products; 
     } 

希望這能解決您的加載速度慢的問題,是不是太晚了在這個時候。