0
從一頁到下一頁,有一個屬性在用戶界面中綁定,這個屬性需要一個浪費時間的操作,所以頁面不會很長時間,是有什麼辦法可以提高速度。窗口手機頁面加載速度
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {
string value = string.Empty;
IDictionary<string, string> queryString = this.NavigationContext.QueryString;
if (queryString.ContainsKey("Type"))
{
this.Type = queryString["Type"];
new Thread(() => {
mtv.AddDistanceForList();
}).Start();
}
else
{
GetMovieThreater();
}
base.OnNavigatedTo(e); }
private void GetMovieThreater() {
string movieId = PhoneApplicationService.Current.State["MovieId"] as string;
mtv.SelectThreaterByMovie(movieId);
mtv.AddDistanceForList(); }
在視圖模型是這樣的:
private ObservableCollection<Threater> threaters; public ObservableCollection<Threater> Threaters {
get { return threaters; }
set
{
if (threaters != value)
{
threaters = value;
NotifyPropertyChanged("Threaters");
}
} }
private CollectionViewSource filteredThreater; public CollectionViewSource FilteredThreater {
get { return filteredThreater; }
set
{
filteredThreater = value;
NotifyPropertyChanged("FilteredThreater");
} } This function wate time!!! public void SelectThreaterByMovie(string movieId) {
Threaters.Clear();
if(MovieDataAllMovies.Threaters!=null)
{
foreach(var i in MovieDataAllMovies.MoviePlans){
if (i.MovieId == movieId)
{
MovieDataAllMovies.Threaters.ForEach((e) =>
{
if (i.TheaterId == e.Tid.ToString())
{
Threaters.Add(e);
}
});
}
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
this.FilteredThreater.Source = Threaters;
}); } }