mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-29 13:02:05 +03:00
IoC and NavigationService implementation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace MyFriendsAround.WP7.Helpers.Navigation
|
||||
{
|
||||
public interface IPageNavigation
|
||||
{
|
||||
event NavigatingCancelEventHandler Navigating;
|
||||
object CurrentContext { get; }
|
||||
void NavigateTo(Uri pageUri);
|
||||
void NavigateTo(Uri pageUri, object context);
|
||||
void GoBack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Ink;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
using Microsoft.Phone.Controls;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace MyFriendsAround.WP7.Helpers.Navigation
|
||||
{
|
||||
public class PageNavigation : IPageNavigation
|
||||
{
|
||||
|
||||
private PhoneApplicationFrame mainFrame;
|
||||
private bool EnsureMainFrame()
|
||||
{
|
||||
if (mainFrame != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
mainFrame = Application.Current.RootVisual as PhoneApplicationFrame;
|
||||
if (mainFrame != null)
|
||||
{
|
||||
// Could be null if the app runs inside a design tool
|
||||
mainFrame.Navigating += (s, e) =>
|
||||
{
|
||||
if (Navigating != null)
|
||||
{
|
||||
Navigating(s, e);
|
||||
}
|
||||
};
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#region IPageNavigation implementation
|
||||
|
||||
public event NavigatingCancelEventHandler Navigating;
|
||||
|
||||
private object currentContext;
|
||||
public object CurrentContext
|
||||
{
|
||||
get { return this.currentContext; }
|
||||
}
|
||||
|
||||
public void NavigateTo(Uri pageUri)
|
||||
{
|
||||
if (pageUri == null)
|
||||
throw new ArgumentNullException("uri");
|
||||
if (EnsureMainFrame())
|
||||
this.NavigateTo(pageUri, null);
|
||||
}
|
||||
|
||||
public void NavigateTo(Uri pageUri, object context)
|
||||
{
|
||||
if (pageUri == null)
|
||||
throw new ArgumentNullException("uri");
|
||||
if (EnsureMainFrame())
|
||||
{
|
||||
this.currentContext = context;
|
||||
mainFrame.Navigate(pageUri);
|
||||
}
|
||||
}
|
||||
|
||||
public void GoBack()
|
||||
{
|
||||
if (EnsureMainFrame() && mainFrame.CanGoBack)
|
||||
{
|
||||
mainFrame.GoBack();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user