From a3d3a15a88551c8494736bb7f1aec186d170d00f Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 20 Dec 2017 01:00:02 +0100 Subject: [PATCH] Added routing to UI project Added Ninject Added Fody --- src/Artemis.UI/App.xaml | 5 +- src/Artemis.UI/AppBootstrapper.cs | 59 ++++++++++ src/Artemis.UI/Artemis.UI.csproj | 34 +++++- src/Artemis.UI/FodyWeavers.xml | 4 + src/Artemis.UI/MainWindow.xaml | 105 +++++++++++++----- src/Artemis.UI/MainWindow.xaml.cs | 7 +- src/Artemis.UI/Ninject/ViewsModule.cs | 13 +++ .../Properties/Resources.Designer.cs | 10 ++ src/Artemis.UI/Properties/Resources.resx | 3 + src/Artemis.UI/Resources/bow.svg | 44 ++++++++ src/Artemis.UI/ViewModels/MainViewModel.cs | 18 ++- src/Artemis.UI/Views/MainView.xaml | 10 +- src/Artemis.UI/Views/MainView.xaml.cs | 22 +++- src/Artemis.UI/packages.config | 5 +- 14 files changed, 288 insertions(+), 51 deletions(-) create mode 100644 src/Artemis.UI/AppBootstrapper.cs create mode 100644 src/Artemis.UI/FodyWeavers.xml create mode 100644 src/Artemis.UI/Ninject/ViewsModule.cs create mode 100644 src/Artemis.UI/Resources/bow.svg diff --git a/src/Artemis.UI/App.xaml b/src/Artemis.UI/App.xaml index 80121ce34..7110a4142 100644 --- a/src/Artemis.UI/App.xaml +++ b/src/Artemis.UI/App.xaml @@ -1,7 +1,6 @@  @@ -46,8 +45,10 @@ + + + - diff --git a/src/Artemis.UI/AppBootstrapper.cs b/src/Artemis.UI/AppBootstrapper.cs new file mode 100644 index 000000000..f1d87304a --- /dev/null +++ b/src/Artemis.UI/AppBootstrapper.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using Artemis.UI.Ninject; +using Artemis.UI.ViewModels; +using Ninject; +using ReactiveUI; +using ReactiveUI.Fody.Helpers; +using Splat; + +namespace Artemis.UI +{ + public class AppBootstrapper : ReactiveObject, IScreen + { + public AppBootstrapper() + { + Router = new RoutingState(); + Kernel = new StandardKernel(new ViewsModule()); + + // Configure the Ninject kernel and set it up as the default for ReactiveUI + SetupNinject(Kernel); + + // Update the title on view change + this.WhenAnyValue(x => x.Router.CurrentViewModel) + .Subscribe(o => o.Subscribe(vm => { ViewTitle = vm != null ? vm.UrlPathSegment : ""; })); + + // Navigate to the opening page of the application + Router.Navigate.Execute(Kernel.Get()); + } + + public IKernel Kernel { get; set; } + + [Reactive] + public string ViewTitle { get; set; } + + public RoutingState Router { get; } + + private void SetupNinject(IKernel kernel) + { + // Bind the main screen to IScreen + kernel.Bind().ToConstant(this); + + // Set up NInject to do DI + var customResolver = new FuncDependencyResolver( + (service, contract) => + { + if (contract != null) return kernel.GetAll(service, contract); + var items = kernel.GetAll(service); + var list = items.ToList(); + return list; + }, + (factory, service, contract) => + { + var binding = kernel.Bind(service).ToMethod(_ => factory()); + if (contract != null) binding.Named(contract); + }); + Locator.Current = customResolver; + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 65e0f0f74..7ea1667d1 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -13,6 +13,8 @@ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true + + AnyCPU @@ -46,11 +48,17 @@ ..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + ..\packages\Ninject.3.3.4\lib\net45\Ninject.dll + ..\packages\reactiveui-core.7.4.0\lib\Net45\ReactiveUI.dll - - ..\packages\Splat.1.4.0\lib\Net45\Splat.dll + + ..\packages\ReactiveUI.Fody.2.2.11\lib\net45\ReactiveUI.Fody.Helpers.dll + + + ..\packages\Splat.1.6.0\lib\Net45\Splat.dll @@ -91,6 +99,8 @@ MSBuild:Compile Designer + + MainView.xaml @@ -137,7 +147,9 @@ - + + Designer + @@ -148,5 +160,21 @@ + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/src/Artemis.UI/FodyWeavers.xml b/src/Artemis.UI/FodyWeavers.xml new file mode 100644 index 000000000..e36b845f9 --- /dev/null +++ b/src/Artemis.UI/FodyWeavers.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Artemis.UI/MainWindow.xaml b/src/Artemis.UI/MainWindow.xaml index eb3c79412..64346ce33 100644 --- a/src/Artemis.UI/MainWindow.xaml +++ b/src/Artemis.UI/MainWindow.xaml @@ -1,22 +1,75 @@  - + 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:metro="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:views="clr-namespace:Artemis.UI.Views" + xmlns:reactiveUi="http://reactiveui.net" + mc:Ignorable="d" + GlowBrush="{DynamicResource AccentColorBrush}" + FontFamily="{StaticResource DefaultFont}" + Title="Artemis" + d:DesignHeight="639.411" + d:DesignWidth="1113.251"> + + + + + + + + + + + + + + + + + + + + + - @@ -34,30 +87,24 @@ Mode="PrimaryMid" DockPanel.Dock="Top"> - + x:Name="MenuToggleButton" /> +