Skip to content

Commit

Permalink
全部使用上拉刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Mar 8, 2012
1 parent 82dbd1e commit d17a272
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 161 deletions.
19 changes: 6 additions & 13 deletions BoardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:local="clr-namespace:sbbs_client_wp7"
xmlns:custom="clr-namespace:CustomControls"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -19,9 +20,7 @@
toolkit:TiltEffect.IsTiltEnabled="True">

<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator Text="载入中..."
IsVisible="{Binding IsLoading}"
IsIndeterminate="{Binding IsLoading}"/>
<shell:ProgressIndicator Text="载入中..." IsVisible="{Binding IsLoading}" IsIndeterminate="{Binding IsLoading}"/>
</shell:SystemTray.ProgressIndicator>

<toolkit:TransitionService.NavigationInTransition>
Expand Down Expand Up @@ -60,16 +59,10 @@
</StackPanel>

<!--ContentPanel - place additional content here-->
<local:ExtendedListBox x:Name="TopicsList" ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource TopicDataTemplate}"
SelectionChanged="TopicsList_Selected"
NextPage="TopicsList_NextPage"
Grid.Row="1" Margin="12,0,12,0">
<local:ExtendedListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</local:ExtendedListBox.ItemContainerStyle>
</local:ExtendedListBox>
<custom:ExtendedListBox x:Name="TopicsList" ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource TopicDataTemplate}"
SelectionChanged="TopicsList_Selected"
NextPage="TopicsList_NextPage"
Grid.Row="1" Margin="12,0,12,0"/>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
Expand Down
4 changes: 1 addition & 3 deletions BoardPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace sbbs_client_wp7
{
using Sbbs;
using CustomControls;

public partial class BoardPage : PhoneApplicationPage
{
Expand Down Expand Up @@ -126,9 +127,6 @@ private void LoadTopics(bool append = false)
++currentPage;
foreach (TopicViewModel topic in topics)
App.ViewModel.CurrentBoard.Topics.Add(topic);

// 叠加完毕时往后翻页

}
else
{
Expand Down
33 changes: 22 additions & 11 deletions Controls/ExtendedListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,51 @@
using Microsoft.Phone.Controls;
using System.Windows.Controls.Primitives;
using System.Collections;
using System.Collections.Specialized;

namespace sbbs_client_wp7
namespace CustomControls
{
public class ExtendedListBox : ListBox
{
protected bool _isBouncy = false;
private bool alreadyHookedScrollEvents = false;

TextBlock LoadMoreText;

// 属性:是否完全载入
public bool IsFullyLoaded
// 属性:底部提示文字
public TextBlock LoadMore
{
get { return (bool)GetValue(IsFullyLoadedProperty); }
set { SetValue(IsFullyLoadedProperty, value); }
get { return base.GetValue(LoadMoreProperty) as TextBlock; }
set { base.SetValue(LoadMoreProperty, value); }
}

public static readonly DependencyProperty IsFullyLoadedProperty =
DependencyProperty.Register("IsFullyLoaded", typeof(bool), typeof(ExtendedListBox), new PropertyMetadata(false));
public static readonly DependencyProperty LoadMoreProperty =
DependencyProperty.Register("LoadMore", typeof(TextBlock), typeof(ExtendedListBox), null);

// 属性:是否完全载入
public bool IsFullyLoaded { get; set; }

// 事件:拖到边界处
public delegate void OnNextPage(object sender, NextPageEventArgs e);
public event OnNextPage NextPage;

// 当列表内无内容时隐藏文字
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
{
base.OnItemsChanged(e);
ApplyTemplate();

LoadMore.Visibility = (!IsFullyLoaded && Items.Count > 0) ? Visibility.Visible : Visibility.Collapsed;
}

public ExtendedListBox()
{
DefaultStyleKey = typeof(ExtendedListBox);
this.Loaded += new RoutedEventHandler(ListBox_Loaded);
}

public override void OnApplyTemplate()
{
base.OnApplyTemplate();

LoadMoreText = (TextBlock)GetTemplateChild("LoadMoreText");
LoadMore = (TextBlock)GetTemplateChild("LoadMore");
}

private void ListBox_Loaded(object sender, RoutedEventArgs e)
Expand Down
59 changes: 17 additions & 42 deletions MailboxPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:custom="clr-namespace:CustomControls"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -64,54 +65,28 @@
<!--Pivot Control-->
<controls:Pivot LoadedPivotItem="Pivot_LoadedPivotItem" x:Name="MailboxPivot" Title="虎踞龙蟠BBS">
<controls:PivotItem Header="收件箱">
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding InboxItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore1" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
<custom:ExtendedListBox x:Name="InboxList"
ItemsSource="{Binding InboxItems}"
ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected"
NextPage="BoxList_NextPage"/>
</controls:PivotItem>

<controls:PivotItem Header="发件箱">
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding SentItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore2" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
<custom:ExtendedListBox x:Name="SentList"
ItemsSource="{Binding SentItems}"
ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected"
NextPage="BoxList_NextPage"/>
</controls:PivotItem>

<controls:PivotItem Header="垃圾箱">
<ScrollViewer>
<StackPanel>
<ListBox ItemsSource="{Binding DeletedItems}" ItemTemplate="{StaticResource MailDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Mail_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" Margin="-12 0" x:Name="LoadMore3" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>
<custom:ExtendedListBox x:Name="DeletedList"
ItemsSource="{Binding DeletedItems}"
ItemTemplate="{StaticResource MailDataTemplate}"
SelectionChanged="Mail_Selected"
NextPage="BoxList_NextPage">
</custom:ExtendedListBox>
</controls:PivotItem>
</controls:Pivot>
</Grid>
Expand Down
26 changes: 9 additions & 17 deletions MailboxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace sbbs_client_wp7
{
using Sbbs;
using CustomControls;

public partial class MailboxPage : PhoneApplicationPage
{
Expand All @@ -28,8 +29,8 @@ private void SetLoading()
App.ViewModel.Mailbox.IsLoading = isLoading[0] | isLoading[1] | isLoading[2];
}

// 载入按钮集合
Button[] LoadMore = { null, null, null };
// 列表集合
ExtendedListBox[] List = { null, null, null };

public MailboxPage()
{
Expand All @@ -40,9 +41,9 @@ public MailboxPage()

DataContext = App.ViewModel.Mailbox;

LoadMore[0] = LoadMore1;
LoadMore[1] = LoadMore2;
LoadMore[2] = LoadMore3;
List[0] = InboxList;
List[1] = SentList;
List[2] = DeletedList;
}

// 进入页面时根据参数切换到指定的页面
Expand Down Expand Up @@ -144,16 +145,7 @@ private void LoadMailbox(int type, bool append = false)
}

// 判断是否显示下一页
if (mails.Count < pageSize)
{
LoadMore[type].Visibility = Visibility.Collapsed;
LoadMore[type].IsEnabled = false;
}
else
{
LoadMore[type].Visibility = Visibility.Visible;
LoadMore[type].IsEnabled = true;
}
List[type].IsFullyLoaded = mails.Count < pageSize;
}
});
}
Expand All @@ -165,8 +157,8 @@ private void Refresh_Click(object sender, EventArgs e)
LoadMailbox(MailboxPivot.SelectedIndex);
}

// 载入更多
private void LoadMore_Click(object sender, RoutedEventArgs e)
// 载入下一页
private void BoxList_NextPage(object sendor, NextPageEventArgs e)
{
LoadMailbox(MailboxPivot.SelectedIndex, true);
}
Expand Down
36 changes: 36 additions & 0 deletions Themes/generic.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:custom="clr-namespace:CustomControls">

<Style TargetType="custom:ExtendedListBox">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="custom:ExtendedListBox">
<ScrollViewer x:Name="ScrollViewer" Foreground="{TemplateBinding Foreground}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<StackPanel>
<ItemsPresenter x:Name="Content"/>
<TextBlock x:Name="LoadMore" Visibility="Collapsed" HorizontalAlignment="Center" Margin="0 5 0 25" Text="载入下一页..." Foreground="{StaticResource PhoneAccentBrush}" FontSize="{StaticResource PhoneFontSizeNormal}" />
</StackPanel>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
27 changes: 8 additions & 19 deletions TopicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:custom="clr-namespace:CustomControls"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -13,13 +14,11 @@
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
shell:SystemTray.Opacity="{Binding IsLoaded, Converter={StaticResource LoadedOpacityConerter}}"
shell:SystemTray.Opacity="{Binding IsLoading, Converter={StaticResource LoadedOpacityConerter}, ConverterParameter=true}"
d:DataContext="{d:DesignData SampleData/CurrentTopicViewModelSampleData.xaml}">

<shell:SystemTray.ProgressIndicator>
<shell:ProgressIndicator Text="载入中..."
IsVisible="{Binding IsLoaded, Converter={StaticResource BoolReverseConverter}}"
IsIndeterminate="{Binding IsLoaded, Converter={StaticResource BoolReverseConverter}}"/>
<shell:ProgressIndicator Text="载入中..." IsVisible="{Binding IsLoading}" IsIndeterminate="{Binding IsLoading}"/>
</shell:SystemTray.ProgressIndicator>

<toolkit:TransitionService.NavigationInTransition>
Expand Down Expand Up @@ -77,21 +76,11 @@
<TextBlock x:Name="PageTitle" Text="{Binding Title}" Margin="0,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</ScrollViewer>
</StackPanel>

<ScrollViewer Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<ListBox x:Name="TopicsList" ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource ContentDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Visibility="Collapsed" toolkit:TiltEffect.IsTiltEnabled="True" Margin="-12 0" x:Name="LoadMore" Content="载入更多" Click="LoadMore_Click"/>
</StackPanel>
</ScrollViewer>

<custom:ExtendedListBox Grid.Row="1" Margin="12,0,12,0"
x:Name="TopicsList" ItemsSource="{Binding Topics}" ItemTemplate="{StaticResource ContentDataTemplate}"
SelectionChanged="TopicsList_SelectionChanged"
NextPage="TopicsList_NextPage"/>
</Grid>

<phone:PhoneApplicationPage.ApplicationBar>
Expand Down
Loading

0 comments on commit d17a272

Please sign in to comment.