-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from fossmium/replace-mvvmlight
Removed MVVM Light and replaced it partially with MVVM Toolkit.
- Loading branch information
Showing
17 changed files
with
257 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
|
||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Media.Animation; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
namespace OneDrive_Cloud_Player.Services | ||
{ | ||
public static class NavigationService | ||
{ | ||
public static event NavigatedEventHandler Navigated; | ||
|
||
public static event NavigationFailedEventHandler NavigationFailed; | ||
|
||
private static Frame _frame; | ||
private static object _lastParamUsed; | ||
|
||
public static Frame Frame | ||
{ | ||
get | ||
{ | ||
if (_frame == null) | ||
{ | ||
_frame = Window.Current.Content as Frame; | ||
RegisterFrameEvents(); | ||
} | ||
|
||
return _frame; | ||
} | ||
|
||
set | ||
{ | ||
UnregisterFrameEvents(); | ||
_frame = value; | ||
RegisterFrameEvents(); | ||
} | ||
} | ||
|
||
public static bool CanGoBack => Frame.CanGoBack; | ||
|
||
public static bool CanGoForward => Frame.CanGoForward; | ||
|
||
public static bool GoBack() | ||
{ | ||
if (CanGoBack) | ||
{ | ||
Frame.GoBack(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static void GoForward() => Frame.GoForward(); | ||
|
||
public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null) | ||
{ | ||
if (pageType == null || !pageType.IsSubclassOf(typeof(Page))) | ||
{ | ||
throw new ArgumentException($"Invalid pageType '{pageType}', please provide a valid pageType.", nameof(pageType)); | ||
} | ||
|
||
// Don't open the same page multiple times | ||
if (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(_lastParamUsed))) | ||
{ | ||
var navigationResult = Frame.Navigate(pageType, parameter, infoOverride); | ||
if (navigationResult) | ||
{ | ||
_lastParamUsed = parameter; | ||
} | ||
|
||
return navigationResult; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public static bool Navigate<T>(object parameter = null, NavigationTransitionInfo infoOverride = null) | ||
where T : Page | ||
{ | ||
return Navigate(typeof(T), parameter, infoOverride); | ||
} | ||
|
||
private static void RegisterFrameEvents() | ||
{ | ||
if (_frame != null) | ||
{ | ||
_frame.Navigated += Frame_Navigated; | ||
_frame.NavigationFailed += Frame_NavigationFailed; | ||
} | ||
} | ||
|
||
private static void UnregisterFrameEvents() | ||
{ | ||
if (_frame != null) | ||
{ | ||
_frame.Navigated -= Frame_Navigated; | ||
_frame.NavigationFailed -= Frame_NavigationFailed; | ||
} | ||
} | ||
|
||
private static void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e) => NavigationFailed?.Invoke(sender, e); | ||
|
||
private static void Frame_Navigated(object sender, NavigationEventArgs e) => Navigated?.Invoke(sender, e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.