[英]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.