IoC and NavigationService implementation

This commit is contained in:
2011-03-25 11:22:57 +02:00
parent 98c8cf3f94
commit f069ee7010
31 changed files with 1139 additions and 73 deletions
@@ -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
}
}