从一个Page到下一个Page,在UI中绑定了一个属性,这个属性需要浪费时间操作一次,所以页面很长时间不来了,有什么办法可以提高速度。
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;
}); } }