[英]WP7 pivot control performance is NOT smooth for me
好的,我的应用程序工作,我只是讨厌切换透视项目时看到的性能。 我随机得到口吃和挂断。 我真的很喜欢线程,因为我来自web开发背景。 有什么我可以做的不同,以加快我的应用程序?
这是从“Twist!”切换的主页面。 应用程序。 在“观察列表”和“我的列表”项目之间切换时,最大的问题就出现了。
private void panTwist_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
switch (panTwist.SelectedIndex)
{
case 0: //Watch List
App.vmTweet.LoadMore = false;
DataContext = App.vmTweet;
if (!App.vmTweet.IsWatchListTweetsLoaded)
{
LoadWatchList(false);
}
break;
case 1: //menu
ApplicationBar = null;
SetMenuDisplay();
break;
case 2: //My Lists
ApplicationBar = null;
DataContext = App.vmTwitterList;
if (!App.vmTwitterList.IsMyListsLoaded)
{
GetMyLists();
}
MyListsSetDisplay();
break;
default:
break;
}
}
这是我的“Wiki-Reef”应用程序的代码。 这个表现得更糟......
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
App.vmCoral.GetTopCorals();
}
else
{
//get saved corals from device
MessageBox.Show("Your phone does not have a connection to the internet, so the results you see could be empty or outdated.");
App.vmCoral.GetSavedTopCorals();
}
}
break;
case 2: //new corals
if (!App.vmCoral.IsNewDataLoaded)
{
App.vmCoral.IsNewLoading = true;
if (App.HasConnectivity)
{
//get corals from web
App.vmCoral.GetNewCorals();
}
else
{
//get saved corals from device
MessageBox.Show("Your phone does not have a connection to the internet, so the results you see could be empty or outdated.");
App.vmCoral.GetSavedNewCorals();
}
}
break;
default:
break;
}
}
我同意Rico的观点。 这听起来像是在进行远程调用(调用Web服务)。 如果是这种情况,请确保使用HttpWebRequest而不是WebClient。 使用WebClient时,它会阻止UI线程。 直接从MSDN关于使用WebClient:
“在处理完成之前,用户界面将无法响应,导致用户体验不佳,尤其是在处理的数据集很大的情况下。”
这是链接 。 我建议阅读所有内容,因为它包含有关提高该页面上的应用程序性能的其他提示。
不要重置DataContext。
尝试使用此代码。 这遵循MVVM(请参阅http://msdn.microsoft.com/en-us/magazine/dd419663.aspx )并且不重置DataContext。
查看型号:
public class MainPageViewModel
{
public MainPageViewModel()
{
ItemsOfPivotOne = new ObservableCollection<ItemOfPivotOne>();
ItemsOfPivotTwo = new ObservableCollection<ItemOfPivotOne>();
}
public void LoadPivotOne()
{
// add your http logic here and add elements like this:
ItemsOfPivotOne.Add(item);
}
public void LoadPivotOne()
{
// add your http logic here and add elements like this:
ItemsOfPivotTwo.Add(item);
}
public ObservableCollection<ItemOfPivotOne> ItemsOfPivotOne {get; set;}
public ObservableCollection<ItemOfPivotTwo> ItemsOfPivotTwo {get; set;}
}
页面代码背后:
public class MainPage
{
public MainPageViewModel Model { get { return (MainPageViewModel)Resources["viewModel"]; } }
private void PivotSelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (panTwist.SelectedIndex)
{
case 0:
Model.LoadPivotOne();
break;
case 1:
Model.LoadPivotTwo();
break;
}
}
}
具有资源的视图模型实例化的XAML代码:
<phone:PhoneApplicationPage x:Class="MyNamespace.MainPage" ... >
<phone:PhoneApplicationPage.Resources>
<viewModels:MainPageViewModel x:Key="viewModel" />
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" DataContext="{StaticResource viewModel}">
<controls:Pivot Title="MY APPLICATION">
<controls:PivotItem Header="Pivot 1">
<ListBox ItemsSource="{Binding ItemsOfPivotOne}" />
</controls:PivotItem>
<controls:PivotItem Header="Pivot 2">
<ListBox ItemsSource="{Binding ItemsOfPivotTwo}" />
</controls:PivotItem>
...
我希望这有帮助...如果不在这里问我......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.