Created
February 29, 2016 14:51
-
-
Save vmilev/c00b40965d3dc031bfad to your computer and use it in GitHub Desktop.
Share Code Blog 2
This file contains hidden or 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
public partial class App : Application | |
{ | |
private static readonly IUnityContainer Container = new UnityContainer(); | |
public static INavigationService NavigationService { get; private set; } | |
// Other code omitted for conciseness | |
internal static void InitializeNavigationService(NavigationService service) | |
{ | |
NavigationService = new SimpleNavigationService(service); | |
Container.RegisterInstance<INavigationService>(NavigationService); | |
} | |
} |
This file contains hidden or 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
protected override Type GetPageType(string pageToken) | |
{ | |
var assemblyQualifiedAppType = this.GetType().AssemblyQualifiedName; | |
var pageNameWithParameter = assemblyQualifiedAppType.Replace(this.GetType().FullName, this.GetType().Namespace + ".Views.{0}"); | |
var viewFullName = string.Format(CultureInfo.InvariantCulture, pageNameWithParameter, pageToken); | |
var viewType = Type.GetType(viewFullName); | |
if (viewType == null) | |
{ | |
var resourceLoader = ResourceLoader.GetForCurrentView(PrismConstants.StoreAppsInfrastructureResourceMapId); | |
throw new ArgumentException( | |
string.Format(CultureInfo.InvariantCulture, resourceLoader.GetString("DefaultPageTypeLookupErrorMessage"), pageToken, this.GetType().Namespace + ".Views"), | |
"pageToken"); | |
} | |
return viewType; | |
} |
This file contains hidden or 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
public class MainPageViewModel : ViewModelBase | |
{ | |
private readonly ICommand navigateAway; | |
private INavigationService navService; | |
public ICommand NavigateAway | |
{ | |
get { return this.navigateAway; } | |
} | |
public MainPageViewModel(INavigationService navService) | |
{ | |
this.navService = navService; | |
this.navigateAway = new DelegateCommand<int?>(this.TestCommandCallback); | |
} | |
private void TestCommandCallback(int? obj) | |
{ | |
this.navService.Navigate("SecondPage", null); | |
} | |
} |
This file contains hidden or 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
<Window x:Class="MyApp.Desktop.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" Height="350" Width="525"> | |
<Grid> | |
<Frame NavigationUIVisibility="Hidden" x:Name="navigationFrame"> | |
</Frame> | |
</Grid> | |
</Window> |
This file contains hidden or 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
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
App.InitializeNavigationService(navigationFrame.NavigationService); | |
App.NavigationService.Navigate("MainPage", null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment