From 52f21a6d579dabea7c0a09a4dc358c1a4c29b2d5 Mon Sep 17 00:00:00 2001 From: tobiichiamane Date: Fri, 8 May 2020 20:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=80=E4=BA=9B=E5=AF=B9Ma?= =?UTF-8?q?inPage=E7=9A=84=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PixivFSUWP/Data/OverAll.cs | 1 + PixivFSUWP/MainPage.xaml.cs | 1 + PixivFSUWP/SettingsPage.xaml.cs | 8 ++++---- PixivFSUWP/UserDetailPage.xaml.cs | 22 ++++++++-------------- PixivFSUWP/WaterfallPage.xaml.cs | 21 +++++++-------------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/PixivFSUWP/Data/OverAll.cs b/PixivFSUWP/Data/OverAll.cs index e796801..ef66734 100644 --- a/PixivFSUWP/Data/OverAll.cs +++ b/PixivFSUWP/Data/OverAll.cs @@ -31,6 +31,7 @@ public static class OverAll public static BookmarkIllustsCollection BookmarkList { get; private set; } public static FollowingIllustsCollection FollowingList { get; private set; } public static RankingIllustsCollection RankingList { get; private set; } + public static MainPage TheMainPage { get; set; } public static void RefreshRecommendList() { diff --git a/PixivFSUWP/MainPage.xaml.cs b/PixivFSUWP/MainPage.xaml.cs index f24bf9c..5e3b2ad 100644 --- a/PixivFSUWP/MainPage.xaml.cs +++ b/PixivFSUWP/MainPage.xaml.cs @@ -39,6 +39,7 @@ public MainPage() view.TitleBar.ButtonInactiveForegroundColor = Colors.Gray; view.Title = ""; btnExperimentalWarning.Visibility = GlobalBaseAPI.ExperimentalConnection ? Visibility.Visible : Visibility.Collapsed; + TheMainPage = this; } bool _programmablechange = false; diff --git a/PixivFSUWP/SettingsPage.xaml.cs b/PixivFSUWP/SettingsPage.xaml.cs index d38f1c7..fbecab6 100644 --- a/PixivFSUWP/SettingsPage.xaml.cs +++ b/PixivFSUWP/SettingsPage.xaml.cs @@ -45,7 +45,7 @@ public void SetBackFlag(bool value) protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - ((Frame.Parent as Grid)?.Parent as MainPage)?.SelectNavPlaceholder(GetResourceString("SettingsPagePlain")); + TheMainPage?.SelectNavPlaceholder(GetResourceString("SettingsPagePlain")); } protected override void OnNavigatedFrom(NavigationEventArgs e) @@ -54,7 +54,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e) if (!_backflag) { Data.Backstack.Default.Push(typeof(SettingsPage), null); - ((Frame.Parent as Grid)?.Parent as MainPage)?.UpdateNavButtonState(); + TheMainPage?.UpdateNavButtonState(); } } @@ -154,7 +154,7 @@ private void BtnLogout_Click(object sender, RoutedEventArgs e) catch { } finally { - ((Frame.Parent as Grid).Parent as MainPage).Frame.Navigate(typeof(LoginPage)); + TheMainPage.Frame.Navigate(typeof(LoginPage)); } } @@ -215,7 +215,7 @@ private void ComboBox_DropDownClosed(object sender, object e) ApplicationData.Current.LocalSettings.Values["ColorTheme"] = true; break; } - _ = ((Frame.Parent as Grid)?.Parent as MainPage)?.ShowTip(GetResourceString("RestartApplyColorTheme")); + _ = TheMainPage?.ShowTip(GetResourceString("RestartApplyColorTheme")); } } } diff --git a/PixivFSUWP/UserDetailPage.xaml.cs b/PixivFSUWP/UserDetailPage.xaml.cs index b2bbbc7..99f8e7d 100644 --- a/PixivFSUWP/UserDetailPage.xaml.cs +++ b/PixivFSUWP/UserDetailPage.xaml.cs @@ -65,7 +65,7 @@ private void DataTransferManager_DataRequested(DataTransferManager sender, DataR protected override void OnNavigatedTo(NavigationEventArgs e) { - ((Frame.Parent as Grid)?.Parent as MainPage)?.SelectNavPlaceholder(GetResourceString("UserDetailPagePlain")); + TheMainPage?.SelectNavPlaceholder(GetResourceString("UserDetailPagePlain")); userid = (int)e.Parameter; itemsSource = new UserIllustsCollection(userid.ToString()); itemsSource.CollectionChanged += ItemsSource_CollectionChanged; @@ -82,7 +82,7 @@ protected override void OnNavigatedFrom(NavigationEventArgs e) if (!_backflag) { Data.Backstack.Default.Push(typeof(UserDetailPage), userid); - ((Frame.Parent as Grid)?.Parent as MainPage)?.UpdateNavButtonState(); + TheMainPage?.UpdateNavButtonState(); } } @@ -281,13 +281,11 @@ private async void QuickStar_Click(object sender, RoutedEventArgs e) i.Stars--; i.NotifyChange("StarsString"); i.NotifyChange("IsBookmarked"); - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("DeletedBookmarkPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("DeletedBookmarkPlain"), title)); } else { - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("BookmarkDeleteFailedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("BookmarkDeleteFailedPlain"), title)); } } else @@ -310,13 +308,11 @@ private async void QuickStar_Click(object sender, RoutedEventArgs e) i.Stars++; i.NotifyChange("StarsString"); i.NotifyChange("IsBookmarked"); - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkBookmarkedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkBookmarkedPlain"), title)); } else { - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkBookmarkFailedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkBookmarkFailedPlain"), title)); } } } @@ -351,11 +347,9 @@ private async void QuickSave_Click(object sender, RoutedEventArgs e) } var updateStatus = await CachedFileManager.CompleteUpdatesAsync(file); if (updateStatus == FileUpdateStatus.Complete) - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkSavedPlain"), i.Title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkSavedPlain"), i.Title)); else - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); } } } diff --git a/PixivFSUWP/WaterfallPage.xaml.cs b/PixivFSUWP/WaterfallPage.xaml.cs index 6fdc202..4d00afb 100644 --- a/PixivFSUWP/WaterfallPage.xaml.cs +++ b/PixivFSUWP/WaterfallPage.xaml.cs @@ -172,13 +172,11 @@ private async void QuickStar_Click(object sender, RoutedEventArgs e) i.Stars--; i.NotifyChange("StarsString"); i.NotifyChange("IsBookmarked"); - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("DeletedBookmarkPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("DeletedBookmarkPlain"), title)); } else { - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("BookmarkDeleteFailedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("BookmarkDeleteFailedPlain"), title)); } } else @@ -201,13 +199,11 @@ private async void QuickStar_Click(object sender, RoutedEventArgs e) i.Stars++; i.NotifyChange("StarsString"); i.NotifyChange("IsBookmarked"); - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkBookmarkedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkBookmarkedPlain"), title)); } else { - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkBookmarkFailedPlain"), title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkBookmarkFailedPlain"), title)); } } } @@ -244,17 +240,14 @@ private async void QuickSave_Click(object sender, RoutedEventArgs e) } var updateStatus = await CachedFileManager.CompleteUpdatesAsync(file); if (updateStatus == FileUpdateStatus.Complete) - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkSavedPlain"), i.Title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkSavedPlain"), i.Title)); else - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); } } catch { - await ((Frame.Parent as Grid)?.Parent as MainPage)?. - ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); + await TheMainPage?.ShowTip(string.Format(GetResourceString("WorkSaveFailedPlain"), i.Title)); } } }