2011-10-03 48 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