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 78be87a commit ca96302
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 160 deletions.
5 changes: 2 additions & 3 deletions App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<Grid Margin="0 0 0 10">
<Rectangle Fill="{StaticResource PhoneAccentBrush}" Width="8" HorizontalAlignment="Left"/>
<StackPanel Orientation="Vertical" Margin="4 0 0 0">
<TextBlock Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Text="{Binding Title}"/>
<TextBlock Style="{StaticResource PhoneTextLargeStyle}" TextWrapping="Wrap" Text="{Binding Title}"/>
<Grid>
<TextBlock Style="{StaticResource PhoneTextSubtleStyle}" Text="{Binding Author}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 0 10 0">
Expand All @@ -69,12 +69,11 @@
<TextBlock Style="{StaticResource PhoneTextAccentStyle}" Text="{Binding Author}"/>
<TextBlock HorizontalAlignment="Right" Text="{Binding Time, Converter={StaticResource StampDateConverter}}"/>
</Grid>
<RichTextBox Margin="-12 0 0 0">
<RichTextBox Margin="-12 0 0 8">
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</RichTextBox>
<Rectangle Margin="0 2 0 8" HorizontalAlignment="Stretch" Height="1" Fill="{StaticResource PhoneForegroundBrush}" />
</StackPanel>
</DataTemplate>

Expand Down
4 changes: 2 additions & 2 deletions BoardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="BoardName" Text="{Binding EnglishName}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="BoardDescription" Text="{Binding Description}" Margin="9,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Description}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding EnglishName}" Margin="9,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
Expand Down
12 changes: 5 additions & 7 deletions BoardPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public BoardPage()
InitializeComponent();

DataContext = App.ViewModel.CurrentBoard;
this.Loaded += new RoutedEventHandler(Page_Loaded);
}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
}

protected override void OnNavigatedTo(NavigationEventArgs e)
Expand All @@ -55,8 +50,11 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
// 重新加载
App.Service.Board(board, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 还原加载按钮
LoadMore.IsEnabled = true;
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentBoard.IsLoaded = true;
if (error == null)
Expand Down
30 changes: 30 additions & 0 deletions LocalCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO.IsolatedStorage;

namespace sbbs_client_wp7
{
public static class LocalCache
{
public static T Get<T>(string key, T defaultValue)
{
T value;
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue<T>(key, out value))
IsolatedStorageSettings.ApplicationSettings[key] = value = defaultValue;

return value;
}

public static T Get<T>(string key)
{
T value;
if (!IsolatedStorageSettings.ApplicationSettings.TryGetValue<T>(key, out value))
value = default(T);

return value;
}

public static void Set<T>(string key, T value)
{
IsolatedStorageSettings.ApplicationSettings[key] = value;
}
}
}
16 changes: 12 additions & 4 deletions LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,27 @@ public LoginPage()

private void Login_Click(object sender, RoutedEventArgs e)
{
string username = Username.Text;
string password = Password.Password;
App.ViewModel.Login(username, password, delegate(string error)
App.ViewModel.IsLogining = true;
App.Service.Login(Username.Text, Password.Password, delegate(string token, bool success, string error)
{
App.ViewModel.IsLogining = false;
if (error == null)
{
// 保存获得的Token
App.Service.Token = token;
LocalCache.Set<string>("Token", token);

App.ViewModel.IsLogin = true;
this.NavigationService.GoBack();
}
else
else if (!success)
{
MessageBox.Show("用户名密码错误");
}
else
{
MessageBox.Show("网络错误");
}
});
}
}
Expand Down
154 changes: 57 additions & 97 deletions MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,105 +48,65 @@
</toolkit:NavigationOutTransition>
</toolkit:TransitionService.NavigationOutTransition>

<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="MyItemHeaderTemplate">
<Grid>
<ContentPresenter>
<TextBlock Text="{Binding}" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60" />
</ContentPresenter>
</Grid>
</DataTemplate>

<Style x:Key ="SimpleButtonStyle" TargetType="Button">
<Setter Property ="toolkit:TiltEffect.IsTiltEnabled" Value="True"/>
<Setter Property ="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentControl x:Name="ContentContainer"
Content="{ TemplateBinding Content}"
ContentTemplate="{ TemplateBinding ContentTemplate}"
HorizontalContentAlignment =
"{TemplateBinding HorizontalContentAlignment }"
VerticalContentAlignment=
"{TemplateBinding VerticalContentAlignment}"/>
</ControlTemplate>
</Setter.Value>
</Setter >
</Style>
</phone:PhoneApplicationPage.Resources>

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">

<!--Panorama control-->
<controls:Panorama Title="虎踞龙蟠BBS">
<controls:Panorama.TitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="90" Margin="10,60,0,0" />
</DataTemplate>
</controls:Panorama.TitleTemplate>
<!--Panorama control-->
<controls:Panorama Title="虎踞龙蟠BBS" CacheMode="BitmapCache">
<controls:Panorama.TitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" FontSize="90" Margin="10,60,0,0" />
</DataTemplate>
</controls:Panorama.TitleTemplate>

<!--
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/>
</controls:Panorama.Background>
-->

<!-- 十大热帖 -->
<controls:PanoramaItem>
<controls:PanoramaItem.Header>
<TextBlock MouseLeftButtonUp="RefreshTopten_Click" motion:MetroInMotion.Tilt="6" Text="十大热帖" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60"/>
</controls:PanoramaItem.Header>
<ScrollViewer>
<ListBox ItemsSource="{Binding ToptenItems}" ItemTemplate="{StaticResource TopicDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Topten_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</ScrollViewer>
</controls:PanoramaItem>
<!-- 十大热帖 -->
<controls:PanoramaItem>
<controls:PanoramaItem.Header>
<TextBlock motion:MetroInMotion.Tilt="6" MouseLeftButtonUp="RefreshTopten_Click" Text="十大热帖" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60"/>
</controls:PanoramaItem.Header>
<ListBox ItemsSource="{Binding ToptenItems}" ItemTemplate="{StaticResource TopicDataTemplate}"
SelectionChanged="Topten_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PanoramaItem>

<!-- 我的最爱 -->
<controls:PanoramaItem>
<controls:PanoramaItem.Header>
<TextBlock MouseLeftButtonUp="RefreshFavorates_Click" motion:MetroInMotion.Tilt="6" Text="收藏夹" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60"/>
</controls:PanoramaItem.Header>
<ScrollViewer>
<ListBox ItemsSource="{Binding FavoratesItems}" ItemTemplate="{StaticResource BoardDataTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="Favorates_Selected">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</ScrollViewer>
</controls:PanoramaItem>
<!-- 我的最爱 -->
<controls:PanoramaItem>
<controls:PanoramaItem.Header>
<TextBlock motion:MetroInMotion.Tilt="6" MouseLeftButtonUp="RefreshFavorates_Click" Text="收藏夹" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60"/>
</controls:PanoramaItem.Header>
<ListBox ItemsSource="{Binding FavoratesItems}" ItemTemplate="{StaticResource BoardDataTemplate}"
SelectionChanged="Favorates_Selected"
CacheMode="BitmapCache">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</controls:PanoramaItem>

<!-- 我的账户 -->
<controls:PanoramaItem Orientation="Horizontal" Width="565" Header="我的账户" HeaderTemplate="{StaticResource MyItemHeaderTemplate}">
<toolkit:WrapPanel>
<toolkit:WrapPanel.Resources>
<Style TargetType="local:Tile">
<Setter Property="Margin" Value="5"/>
</Style>
</toolkit:WrapPanel.Resources>
<!-- 我的账户 -->
<controls:PanoramaItem Orientation="Horizontal" Width="565">
<controls:PanoramaItem.Header>
<TextBlock Text="我的账户" Foreground="{StaticResource PhoneAccentBrush}" FontSize="60"/>
</controls:PanoramaItem.Header>
<toolkit:WrapPanel>
<toolkit:WrapPanel.Resources>
<Style TargetType="local:Tile">
<Setter Property="Margin" Value="5"/>
</Style>
</toolkit:WrapPanel.Resources>

<local:Tile Title="热门版面"/>
<local:Tile Title="最近浏览"/>
<local:Tile Title="登录" MouseLeftButtonUp="Login_Click" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="注册" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="我的信箱" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="设置" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="退出" MouseLeftButtonUp="Logout_Click" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="关于"/>
</toolkit:WrapPanel>
</controls:PanoramaItem>
</controls:Panorama>
</Grid>
<local:Tile Title="热门版面"/>
<local:Tile Title="最近浏览"/>
<local:Tile Title="登录" MouseLeftButtonUp="Login_Click" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="注册" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}, ConverterParameter=True}"/>
<local:Tile Title="我的信箱" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="设置" Visibility="{Binding IsLogin, Converter={StaticResource BoolVisibleConverter}}"/>
<local:Tile Title="关于"/>
</toolkit:WrapPanel>
</controls:PanoramaItem>
</controls:Panorama>
</phone:PhoneApplicationPage>
16 changes: 9 additions & 7 deletions MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private void Login_Click(object sender, MouseButtonEventArgs e)
// 注销
private void Logout_Click(object sender, MouseButtonEventArgs e)
{
App.ViewModel.IsLogin = false;
MessageBoxResult result = MessageBox.Show("真的要注销吗?", "注销", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
App.ViewModel.IsLogin = false;
}

// 刷新十大
Expand All @@ -78,15 +80,15 @@ private void Favorates_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;

BoardViewModel board = e.AddedItems[0] as BoardViewModel;
// 收藏夹目录暂时不管
if (board.Leaf != true)
return;

this.NavigationService.Navigate(new Uri("/BoardPage.xaml?board=" + board.EnglishName + "&description=" + board.Description, UriKind.Relative));

// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;
}
}

Expand All @@ -95,13 +97,13 @@ private void Topten_Selected(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;

TopicViewModel topic = e.AddedItems[0] as TopicViewModel;

this.NavigationService.Navigate(
new Uri("/TopicPage.xaml?board=" + topic.Board + "&id=" + topic.Id + "&title=" + HttpUtility.UrlEncode(topic.Title), UriKind.Relative));

// 清除选择,否则同样的项目无法点击第二次
(sender as ListBox).SelectedIndex = -1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sbbs/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void DownloadedAndParse<C, R>(object sender, DownloadStringCompletedEventArgs e)
if (result.error != null)
{
// result.error表示有错误
arg.Callback(default(C), false, result.error);
arg.Callback(default(C), true, result.error);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions TopicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="BoardName" Text="{Binding Board}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="BoardDescription" Text="{Binding Title}" TextWrapping="Wrap" Margin="9,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Board}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="{Binding Title}" TextWrapping="Wrap" Margin="9,-7,0,0" Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>

<ScrollViewer Grid.Row="1" Margin="12,0,12,0">
Expand Down
7 changes: 5 additions & 2 deletions TopicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
// 重新加载
App.Service.Topic(board, id, currentPage * pageSize, pageSize, delegate(ObservableCollection<TopicViewModel> topics, bool success, string error)
{
// 还原加载按钮
LoadMore.IsEnabled = true;
// 判断后面是否还有内容
if (error == null && topics.Count < pageSize)
LoadMore.IsEnabled = false;
else
LoadMore.IsEnabled = true;

App.ViewModel.CurrentTopic.IsLoaded = true;
if (error == null)
Expand Down
6 changes: 3 additions & 3 deletions ValueConverters/StampDateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
DateTime now = new DateTime();

if (date.Year == now.Year && date.Month == now.Month && date.Day == now.Day)
return date.ToString("t", culture);
return date.ToString("HH:mm", culture);
else if (date.Year == now.Year)
return date.ToString("m t", culture);
return date.ToString("m HH:mm", culture);
else
return date.ToString("y t", culture);
return date.ToString("y HH:mm", culture);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
Loading

0 comments on commit ca96302

Please sign in to comment.