2011-10-03 31 views
0

我有一個股票未經編輯的芒果的樞軸應用程序的版本,當我運行它的控制它真的很慢,有沒有辦法加快這一點?我的意思是,當我在屏幕上多次快速運行我的手指時 - 就像我在iPhone上所做的那樣,速度非常慢,我的手指脫落了,它仍然在通過窗戶。Windows Phone 7 Stock Pivot Control Slow?

我也在其他應用程序(如IM +,Kik Messenger等)上的真實設備(HTC HD7)上測試此功能......它正常工作。

代碼XAML:

<phone:PhoneApplicationPage 
x:Class="PivotApp1.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}" 
FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
shell:SystemTray.IsVisible="True"> 

<!--LayoutRoot is the root grid where all page content is placed--> 
<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <!--Pivot Control--> 
    <controls:Pivot Title="MY APPLICATION"> 
     <!--Pivot item one--> 
     <controls:PivotItem Header="first"> 
      <!--Double line list with text wrapping--> 
      <ListBox x:Name="FirstListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel Margin="0,0,0,17" Width="432" Height="78"> 
          <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
          <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
     </controls:PivotItem> 

     <!--Pivot item two--> 
     <controls:PivotItem Header="second"> 
      <!--Triple line list no text wrapping--> 
       <ListBox x:Name="SecondListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}"> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Margin="0,0,0,17"> 
           <TextBlock Text="{Binding LineOne}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
           <TextBlock Text="{Binding LineThree}" TextWrapping="NoWrap" Margin="12,-6,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
     </controls:PivotItem> 
    </controls:Pivot> 
</Grid> 

<!--Sample code showing usage of ApplicationBar--> 
<!--<phone:PhoneApplicationPage.ApplicationBar> 
    <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> 
     <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/> 
     <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/> 
     <shell:ApplicationBar.MenuItems> 
      <shell:ApplicationBarMenuItem Text="MenuItem 1"/> 
      <shell:ApplicationBarMenuItem Text="MenuItem 2"/> 
     </shell:ApplicationBar.MenuItems> 
    </shell:ApplicationBar> 
</phone:PhoneApplicationPage.ApplicationBar>--> 

C#MainPage.xaml.cs中代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 

namespace PivotApp1 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 

      // Set the data context of the listbox control to the sample data 
      DataContext = App.ViewModel; 
      this.Loaded += new RoutedEventHandler(MainPage_Loaded); 
     } 

     // Load data for the ViewModel Items 
     private void MainPage_Loaded(object sender, RoutedEventArgs e) 
     { 
      if (!App.ViewModel.IsDataLoaded) 
      { 
       App.ViewModel.LoadData(); 
      } 
     } 
    } 
} 

C#App.xaml.cs代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using Microsoft.Phone.Shell; 

namespace PivotApp1 
{ 
    public partial class App : Application 
    { 
     private static MainViewModel viewModel = null; 

     /// <summary> 
     /// A static ViewModel used by the views to bind against. 
     /// </summary> 
     /// <returns>The MainViewModel object.</returns> 
     public static MainViewModel ViewModel 
     { 
      get 
      { 
       // Delay creation of the view model until necessary 
       if (viewModel == null) 
        viewModel = new MainViewModel(); 

       return viewModel; 
      } 
     } 

     /// <summary> 
     /// Provides easy access to the root frame of the Phone Application. 
     /// </summary> 
     /// <returns>The root frame of the Phone Application.</returns> 
     public PhoneApplicationFrame RootFrame { get; private set; } 

     /// <summary> 
     /// Constructor for the Application object. 
     /// </summary> 
     public App() 
     { 
      // Global handler for uncaught exceptions. 
      UnhandledException += Application_UnhandledException; 

      // Standard Silverlight initialization 
      InitializeComponent(); 

      // Phone-specific initialization 
      InitializePhoneApplication(); 

      // Show graphics profiling information while debugging. 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // Display the current frame rate counters 
       Application.Current.Host.Settings.EnableFrameRateCounter = true; 

       // Show the areas of the app that are being redrawn in each frame. 
       //Application.Current.Host.Settings.EnableRedrawRegions = true; 

       // Enable non-production analysis visualization mode, 
       // which shows areas of a page that are handed off to GPU with a colored overlay. 
       //Application.Current.Host.Settings.EnableCacheVisualization = true; 

       // Disable the application idle detection by setting the UserIdleDetectionMode property of the 
       // application's PhoneApplicationService object to Disabled. 
       // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run 
       // and consume battery power when the user is not using the phone. 
       PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; 
      } 
     } 

     // Code to execute when the application is launching (eg, from Start) 
     // This code will not execute when the application is reactivated 
     private void Application_Launching(object sender, LaunchingEventArgs e) 
     { 
     } 

     // Code to execute when the application is activated (brought to foreground) 
     // This code will not execute when the application is first launched 
     private void Application_Activated(object sender, ActivatedEventArgs e) 
     { 
      // Ensure that application state is restored appropriately 
      if (!App.ViewModel.IsDataLoaded) 
      { 
       App.ViewModel.LoadData(); 
      } 
     } 

     // Code to execute when the application is deactivated (sent to background) 
     // This code will not execute when the application is closing 
     private void Application_Deactivated(object sender, DeactivatedEventArgs e) 
     { 
     } 

     // Code to execute when the application is closing (eg, user hit Back) 
     // This code will not execute when the application is deactivated 
     private void Application_Closing(object sender, ClosingEventArgs e) 
     { 
      // Ensure that required application state is persisted here. 
     } 

     // Code to execute if a navigation fails 
     private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) 
     { 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // A navigation has failed; break into the debugger 
       System.Diagnostics.Debugger.Break(); 
      } 
     } 

     // Code to execute on Unhandled Exceptions 
     private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
     { 
      if (System.Diagnostics.Debugger.IsAttached) 
      { 
       // An unhandled exception has occurred; break into the debugger 
       System.Diagnostics.Debugger.Break(); 
      } 
     } 

     #region Phone application initialization 

     // Avoid double-initialization 
     private bool phoneApplicationInitialized = false; 

     // Do not add any additional code to this method 
     private void InitializePhoneApplication() 
     { 
      if (phoneApplicationInitialized) 
       return; 

      // Create the frame but don't set it as RootVisual yet; this allows the splash 
      // screen to remain active until the application is ready to render. 
      RootFrame = new PhoneApplicationFrame(); 
      RootFrame.Navigated += CompleteInitializePhoneApplication; 

      // Handle navigation failures 
      RootFrame.NavigationFailed += RootFrame_NavigationFailed; 

      // Ensure we don't initialize again 
      phoneApplicationInitialized = true; 
     } 

     // Do not add any additional code to this method 
     private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e) 
     { 
      // Set the root visual to allow the application to render 
      if (RootVisual != RootFrame) 
       RootVisual = RootFrame; 

      // Remove this handler since it is no longer needed 
      RootFrame.Navigated -= CompleteInitializePhoneApplication; 
     } 

     #endregion 
    } 
} 

C# MainViewModel.cs

using System; 
using System.ComponentModel; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Shapes; 
using System.Collections.ObjectModel; 


namespace PivotApp1 
{ 
    public class MainViewModel : INotifyPropertyChanged 
    { 
     public MainViewModel() 
     { 
      this.Items = new ObservableCollection<ItemViewModel>(); 
     } 

     /// <summary> 
     /// A collection for ItemViewModel objects. 
     /// </summary> 
     public ObservableCollection<ItemViewModel> Items { get; private set; } 

     private string _sampleProperty = "Sample Runtime Property Value"; 
     /// <summary> 
     /// Sample ViewModel property; this property is used in the view to display its value using a Binding 
     /// </summary> 
     /// <returns></returns> 
     public string SampleProperty 
     { 
      get 
      { 
       return _sampleProperty; 
      } 
      set 
      { 
       if (value != _sampleProperty) 
       { 
        _sampleProperty = value; 
        NotifyPropertyChanged("SampleProperty"); 
       } 
      } 
     } 

     public bool IsDataLoaded 
     { 
      get; 
      private set; 
     } 

     /// <summary> 
     /// Creates and adds a few ItemViewModel objects into the Items collection. 
     /// </summary> 
     public void LoadData() 
     { 
      // Sample data; replace with real data 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime one", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime two", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime three", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime four", LineTwo = "Nascetur pharetra placerat pulvinar", LineThree = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime five", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime six", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime seven", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime eight", LineTwo = "Nascetur pharetra placerat pulvinar", LineThree = "Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime nine", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime ten", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime eleven", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime twelve", LineTwo = "Nascetur pharetra placerat pulvinar", LineThree = "Ultrices vehicula volutpat maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime thirteen", LineTwo = "Maecenas praesent accumsan bibendum", LineThree = "Maecenas praesent accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime fourteen", LineTwo = "Dictumst eleifend facilisi faucibus", LineThree = "Pharetra placerat pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime fifteen", LineTwo = "Habitant inceptos interdum lobortis", LineThree = "Accumsan bibendum dictumst eleifend facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat" }); 
      this.Items.Add(new ItemViewModel() { LineOne = "runtime sixteen", LineTwo = "Nascetur pharetra placerat pulvinar", LineThree = "Pulvinar sagittis senectus sociosqu suscipit torquent ultrices vehicula volutpat maecenas praesent accumsan bibendum" }); 

      this.IsDataLoaded = true; 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 
     private void NotifyPropertyChanged(String propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 
      if (null != handler) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 
} 

C#ItemViewModel.cs

using System; 
using System.ComponentModel; 
using System.Diagnostics; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 

namespace PivotApp1 
{ 
    public class ItemViewModel : INotifyPropertyChanged 
    { 
     private string _lineOne; 
     /// <summary> 
     /// Sample ViewModel property; this property is used in the view to display its value using a Binding. 
     /// </summary> 
     /// <returns></returns> 
     public string LineOne 
     { 
      get 
      { 
       return _lineOne; 
      } 
      set 
      { 
       if (value != _lineOne) 
       { 
        _lineOne = value; 
        NotifyPropertyChanged("LineOne"); 
       } 
      } 
     } 

     private string _lineTwo; 
     /// <summary> 
     /// Sample ViewModel property; this property is used in the view to display its value using a Binding. 
     /// </summary> 
     /// <returns></returns> 
     public string LineTwo 
     { 
      get 
      { 
       return _lineTwo; 
      } 
      set 
      { 
       if (value != _lineTwo) 
       { 
        _lineTwo = value; 
        NotifyPropertyChanged("LineTwo"); 
       } 
      } 
     } 

     private string _lineThree; 
     /// <summary> 
     /// Sample ViewModel property; this property is used in the view to display its value using a Binding. 
     /// </summary> 
     /// <returns></returns> 
     public string LineThree 
     { 
      get 
      { 
       return _lineThree; 
      } 
      set 
      { 
       if (value != _lineThree) 
       { 
        _lineThree = value; 
        NotifyPropertyChanged("LineThree"); 
       } 
      } 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 
     private void NotifyPropertyChanged(String propertyName) 
     { 
      PropertyChangedEventHandler handler = PropertyChanged; 
      if (null != handler) 
      { 
       handler(this, new PropertyChangedEventArgs(propertyName)); 
      } 
     } 
    } 
} 

我跑的WP 7.1被髮布前幾天在微軟網站上的版本。

我無法弄清楚如何讓應用程序加快速度,因爲它與iOS相比,當我把手指放在手邊並且不平滑時,我將它關閉幾秒鐘,它仍然在努力趕上到我所在的地方。

回答

1

我認爲你使用股票Pivot應用程序模板作爲Windows Phone SDK 7.1(Mango RTM版本)的一部分,在這種情況下應該沒有問題。

我剛剛在本地啓動了模板並且沒有問題地運行它,所以如果可以的話,您可能需要嘗試新的副本。

在模板中沒有C#可以說,它只是加載兩個列表顯示到視圖中的兩個列表框,沒有什麼特別的。當然,這並不是最有效的方式,因爲直到BOTH列表填充之前顯示器纔會呈現,更好地使用某種級別的虛擬化併爲每個視圖單獨加載兩個列表。

我參加了Claus關於在堆疊面板上使用網格的評論,但在大多數情況下,除非在堆疊面板中使用堆疊面板,否則不存在真正的問題,並且堆疊面板如何處理佈局會帶來巨大好處。

讓我知道如果你做什麼都以默認的模板,我會擴大在那裏我可以

+0

嗨,這是一個標準的新項目,至今沒有變化。 XAML是由Microsoft創建的,因爲我沒有改變它,上面我將C#代碼添加到App.xaml.cs和MainPage.xaml.cs中。謝謝。 – Eric

1

您的問題與您的XAML無關。它與在後臺運行的C#代碼有關。

問題是,您正在向UI線程添加沉重的負載,因此在UI線程上運行的pivot之間的導航也很滯後。

我們需要查看相關的C#代碼(code-behind/viewmodel等)以提供更詳細的建議。

至於你的XAML,如果可能,一個好的建議是在你的DataTemplate中使用Grid而不是StackPanel,因爲它改善了列表元素的虛擬化。

+0

嗨,這是一個標準的新項目,沒有變化呢。 XAML是由Microsoft創建的,因爲我沒有改變它,上面我將C#代碼添加到App.xaml.cs和MainPage.xaml.cs中。謝謝。 – Eric