Skip to content

Commit

Permalink
刷新按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 3, 2012
1 parent 0c16edb commit 439f8bf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
2 changes: 1 addition & 1 deletion BoardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False">
<shell:ApplicationBarIconButton IconUri="/Images/new.png" Text="发帖"/>
<shell:ApplicationBarIconButton IconUri="/Images/refresh.png" Text="刷新"/>
<shell:ApplicationBarIconButton Click="Refresh_Click" IconUri="/Images/refresh.png" Text="刷新"/>
<!--<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="MenuItem 1"/>
<shell:ApplicationBarMenuItem Text="MenuItem 2"/>
Expand Down
43 changes: 27 additions & 16 deletions BoardPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,22 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
App.ViewModel.CurrentBoard.EnglishName = board;
App.ViewModel.CurrentBoard.Description = this.NavigationContext.QueryString["description"];

LoadMore.IsEnabled = false;
App.ViewModel.CurrentBoard.IsLoaded = false;

// 清空已有内容
if (App.ViewModel.CurrentBoard.Topics != null)
App.ViewModel.CurrentBoard.Topics.Clear();

// 重新加载
App.Service.Board(board, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentBoard.IsLoaded = true;
if (error == null)
App.ViewModel.CurrentBoard.Topics = topics;
});
currentPage = 0;
LoadTopics();
}
}
}

private void Refresh_Click(object sender, EventArgs e)
{
currentPage = 0;
LoadTopics();
}

private void LoadMore_Click(object sender, RoutedEventArgs e)
{
App.ViewModel.CurrentBoard.IsLoaded = false;
Expand Down Expand Up @@ -104,5 +96,24 @@ private void Topic_Selected(object sender, SelectionChangedEventArgs e)
}
}

private void LoadTopics()
{
LoadMore.IsEnabled = false;
App.ViewModel.CurrentBoard.IsLoaded = false;

// 重新加载
App.Service.Board(App.ViewModel.CurrentBoard.EnglishName, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentBoard.IsLoaded = true;
if (error == null)
App.ViewModel.CurrentBoard.Topics = topics;
});
}
}
}
2 changes: 1 addition & 1 deletion TopicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/new.png" Text="回复"/>
<shell:ApplicationBarIconButton IconUri="/Images/refresh.png" Text="刷新"/>
<shell:ApplicationBarIconButton Click="Refresh_Click" IconUri="/Images/refresh.png" Text="刷新"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

Expand Down
44 changes: 28 additions & 16 deletions TopicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,40 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
App.ViewModel.CurrentTopic.Board = board;
App.ViewModel.CurrentTopic.Title = this.NavigationContext.QueryString["title"];

App.ViewModel.CurrentTopic.IsLoaded = false;
LoadMore.IsEnabled = false;

// 清空已有内容
if (App.ViewModel.CurrentTopic.Topics != null)
App.ViewModel.CurrentTopic.Topics.Clear();

// 重新加载
App.Service.Topic(board, id, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentTopic.IsLoaded = true;
if (error == null)
App.ViewModel.CurrentTopic.Topics = topics;
});
currentPage = 0;
LoadTopics();
}
}
}

private void Refresh_Click(object sender, EventArgs e)
{
currentPage = 0;
LoadTopics();
}

private void LoadTopics()
{
App.ViewModel.CurrentTopic.IsLoaded = false;
LoadMore.IsEnabled = false;

// 重新加载
App.Service.Topic(App.ViewModel.CurrentTopic.Board, App.ViewModel.CurrentTopic.Id, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentTopic.IsLoaded = true;
if (error == null)
App.ViewModel.CurrentTopic.Topics = topics;
});
}
}
}

0 comments on commit 439f8bf

Please sign in to comment.