-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new API for registering navigation, added sample app for demosn…
…trating page navigation
- Loading branch information
Showing
28 changed files
with
555 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31423.177 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppNavigation", "AppNavigation\AppNavigation.csproj", "{A5862B3C-F8B0-4D31-81A7-48BD23B833E7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{A5862B3C-F8B0-4D31-81A7-48BD23B833E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A5862B3C-F8B0-4D31-81A7-48BD23B833E7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A5862B3C-F8B0-4D31-81A7-48BD23B833E7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A5862B3C-F8B0-4D31-81A7-48BD23B833E7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {CB208487-14F8-4AE0-A457-B4099F017809} | ||
EndGlobalSection | ||
EndGlobal |
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,7 @@ | ||
<Application x:Class="AppNavigation.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:AppNavigation"> | ||
<Application.Resources> | ||
</Application.Resources> | ||
</Application> |
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,78 @@ | ||
using System.Windows; | ||
using DryIoc; | ||
using MagicMvvm.Navigation; | ||
|
||
using AppNavigation.ViewModels; | ||
using AppNavigation.ViewModels.Pages; | ||
using AppNavigation.Views; | ||
using AppNavigation.Views.Pages; | ||
|
||
namespace AppNavigation | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
#region Public fields | ||
|
||
// Readonly instance of DryIoc container. | ||
public static readonly IContainer Container = new Container(); | ||
|
||
#endregion | ||
|
||
#region Lifecycle methods | ||
|
||
/// <summary> | ||
/// Application entry point. | ||
/// </summary> | ||
/// <param name="e">Args</param> | ||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
// Call lifecycle methods. | ||
// Note: It's important to call RegisterTypes() method first of all. | ||
RegisterTypes(); | ||
RegisterNavigation(); | ||
|
||
// Resolve MainWindow from container then display main window. | ||
Container.Resolve<MainWindow>().Show(); | ||
base.OnStartup(e); | ||
} | ||
|
||
/// <summary> | ||
/// Registers all data types in the container. | ||
/// </summary> | ||
protected virtual void RegisterTypes() | ||
{ | ||
// Register INavigationManager service as a singleton. | ||
// Note: It's important to register as a singelton otherwise you will get different navigation managers when you try to navigate to views. | ||
Container.Register<INavigationManager, NavigationManager>(Reuse.Singleton); | ||
|
||
// Register views | ||
Container.Register<MainWindow>(Reuse.Singleton); | ||
Container.Register<PageA>(Reuse.Singleton); | ||
Container.Register<PageB>(Reuse.Singleton); | ||
|
||
// Register view models | ||
Container.Register<MainWindowViewModel>(Reuse.Singleton); | ||
Container.Register<PageAViewModel>(Reuse.Singleton); | ||
Container.Register<PageBViewModel>(Reuse.Singleton); | ||
} | ||
|
||
/// <summary> | ||
/// Registers all navigation views. | ||
/// </summary> | ||
protected virtual void RegisterNavigation() | ||
{ | ||
// Resolve singleton instance of the navigation manager from container. | ||
var navigationManager = Container.Resolve<INavigationManager>(); | ||
|
||
// Register all navigable views (pages, user controls etc) with unique names. | ||
// It will register navigation paths in internal registrar of the navigation manager. | ||
navigationManager.RegisterView<PageA>(); | ||
navigationManager.RegisterView<PageB>(); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
samples/03-AppNavigation/AppNavigation/AppNavigation.csproj
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="DryIoc.dll" Version="4.8.0" /> | ||
<PackageReference Include="MagicMvvm.Wpf" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
52 changes: 52 additions & 0 deletions
52
samples/03-AppNavigation/AppNavigation/ViewModels/MainWindowViewModel.cs
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,52 @@ | ||
using System.Windows.Input; | ||
using MagicMvvm; | ||
using MagicMvvm.Commands; | ||
using MagicMvvm.Navigation; | ||
|
||
namespace AppNavigation.ViewModels | ||
{ | ||
public class MainWindowViewModel : ViewModelBase | ||
{ | ||
#region Fields | ||
|
||
private readonly INavigationManager _navigationManager; | ||
|
||
#endregion | ||
|
||
#region Ctor | ||
|
||
public MainWindowViewModel(INavigationManager navigationManager) | ||
{ | ||
// Resolves from container | ||
_navigationManager = navigationManager; | ||
|
||
// Assign action to command using DelegateCommand with command parameter type of string. | ||
NavigateCommand = new DelegateCommand<string>(NavigateToPage); | ||
} | ||
|
||
#endregion | ||
|
||
#region Commands | ||
|
||
public ICommand NavigateCommand { get; } | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
private void NavigateToPage(string page) | ||
{ | ||
// Navigate to page view in the region which is "MainRegion" | ||
if (page == "A") | ||
{ | ||
_navigationManager.RequestNavigate("MainRegion", "PageA"); | ||
} | ||
else if (page == "B") | ||
{ | ||
_navigationManager.RequestNavigate("MainRegion", "PageB"); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
samples/03-AppNavigation/AppNavigation/ViewModels/Pages/PageAViewModel.cs
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,28 @@ | ||
using MagicMvvm; | ||
|
||
namespace AppNavigation.ViewModels.Pages | ||
{ | ||
public class PageAViewModel : ViewModelBase | ||
{ | ||
#region Ctor | ||
|
||
public PageAViewModel() | ||
{ | ||
PageContent = "Page A content"; | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Bindable properties | ||
|
||
private string _pageContent; | ||
public string PageContent | ||
{ | ||
get => _pageContent; | ||
set => SetProperty(ref _pageContent, value); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
samples/03-AppNavigation/AppNavigation/ViewModels/Pages/PageBViewModel.cs
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,28 @@ | ||
using MagicMvvm; | ||
|
||
namespace AppNavigation.ViewModels.Pages | ||
{ | ||
public class PageBViewModel : ViewModelBase | ||
{ | ||
#region Ctor | ||
|
||
public PageBViewModel() | ||
{ | ||
PageContent = "Page B content"; | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Bindable properties | ||
|
||
private string _pageContent; | ||
public string PageContent | ||
{ | ||
get => _pageContent; | ||
set => SetProperty(ref _pageContent, value); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
samples/03-AppNavigation/AppNavigation/Views/MainWindow.xaml
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,40 @@ | ||
<Window x:Class="AppNavigation.Views.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:AppNavigation" | ||
mc:Ignorable="d" | ||
Title="App with navigation" | ||
ResizeMode="NoResize" | ||
WindowStartupLocation="CenterScreen" | ||
Height="450" | ||
Width="800"> | ||
<Grid> | ||
<StackPanel> | ||
<Frame x:Name="mainFrame" | ||
NavigationUIVisibility="Hidden" | ||
Height="350"> | ||
</Frame> | ||
<StackPanel Orientation="Horizontal" | ||
HorizontalAlignment="Left" | ||
Margin="10,10,0,0"> | ||
|
||
<Button Content="Navigate to Page A" | ||
Width="150" | ||
Height="30" | ||
Command="{Binding NavigateCommand}" | ||
CommandParameter="A"> | ||
</Button> | ||
<Button Content="Navigate to Page B" | ||
Margin="10,0,0,0" | ||
Width="150" | ||
Height="30" | ||
Command="{Binding NavigateCommand}" | ||
CommandParameter="B"> | ||
</Button> | ||
</StackPanel> | ||
|
||
</StackPanel> | ||
</Grid> | ||
</Window> |
31 changes: 31 additions & 0 deletions
31
samples/03-AppNavigation/AppNavigation/Views/MainWindow.xaml.cs
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,31 @@ | ||
using System.Windows; | ||
using DryIoc; | ||
using MagicMvvm.Navigation; | ||
using AppNavigation.ViewModels; | ||
|
||
namespace AppNavigation.Views | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
// Bind view model to DataContext | ||
DataContext = App.Container.Resolve<MainWindowViewModel>(); | ||
|
||
// Initialize visual components | ||
InitializeComponent(); | ||
|
||
// Resolve navigation manager from container | ||
var navigationManager = App.Container.Resolve<INavigationManager>(); | ||
|
||
// Register navigtion region with unique name and its view instance | ||
navigationManager.RegisterRegionWithView("MainRegion", this.mainFrame); | ||
|
||
// Navigate to view "PageA" inside region "MainRegion" | ||
navigationManager.RequestNavigate("MainRegion", "PageA"); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/03-AppNavigation/AppNavigation/Views/Pages/PageA.xaml
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,19 @@ | ||
<Page x:Class="AppNavigation.Views.Pages.PageA" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:AppNavigation.Views.Pages" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
Title="PageA"> | ||
|
||
<Grid> | ||
<TextBlock HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
TextWrapping="Wrap" | ||
FontSize="20" | ||
Text="{Binding PageContent}" /> | ||
</Grid> | ||
</Page> |
19 changes: 19 additions & 0 deletions
19
samples/03-AppNavigation/AppNavigation/Views/Pages/PageA.xaml.cs
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,19 @@ | ||
using System.Windows.Controls; | ||
using DryIoc; | ||
using AppNavigation.ViewModels.Pages; | ||
|
||
namespace AppNavigation.Views.Pages | ||
{ | ||
/// <summary> | ||
/// Interaction logic for PageA.xaml | ||
/// </summary> | ||
public partial class PageA : Page | ||
{ | ||
public PageA() | ||
{ | ||
// Bind view model to DataContext | ||
DataContext = App.Container.Resolve<PageAViewModel>(); | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
Oops, something went wrong.