/*
|
In App.xaml:
|
<Application.Resources>
|
<vm:ViewModelLocatorTemplate xmlns:vm="clr-namespace:Bro.UI.ViewModel"
|
x:Key="Locator" />
|
</Application.Resources>
|
|
In the View:
|
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
|
*/
|
|
using System;
|
using System.Linq;
|
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight.Ioc;
|
using GalaSoft.MvvmLight.Views;
|
using Microsoft.Practices.ServiceLocation;
|
using Bro.UI.Model;
|
|
namespace Bro.UI.ViewModel
|
{
|
/// <summary>
|
/// This class contains static references to all the view models in the
|
/// application and provides an entry point for the bindings.
|
/// <para>
|
/// See http://www.mvvmlight.net
|
/// </para>
|
/// </summary>
|
public class ViewModelLocator
|
{
|
static ViewModelLocator()
|
{
|
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
|
|
if (ViewModelBase.IsInDesignModeStatic)
|
{
|
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
|
}
|
else
|
{
|
SimpleIoc.Default.Register<IDataService, DataService>();
|
}
|
|
SimpleIoc.Default.Register<LoginViewModel>();
|
SimpleIoc.Default.Register<MainViewModel>();
|
//SimpleIoc.Default.Register<RunningViewModel>();
|
}
|
|
/// <summary>
|
/// Gets the Main property.
|
/// </summary>
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
|
"CA1822:MarkMembersAsStatic",
|
Justification = "This non-static member is needed for data binding purposes.")]
|
public MainViewModel Main
|
{
|
get
|
{
|
return ServiceLocator.Current.GetInstance<MainViewModel>();
|
}
|
}
|
|
public LoginViewModel Login
|
{
|
get => ServiceLocator.Current.GetInstance<LoginViewModel>();
|
}
|
|
public RunningViewModel Running
|
{
|
get => ServiceLocator.Current.GetInstance<RunningViewModel>();
|
}
|
|
public InformationViewModel Information
|
{
|
get => ServiceLocator.Current.GetInstance<InformationViewModel>();
|
}
|
|
/// <summary>
|
/// Cleans up all the resources.
|
/// </summary>
|
public static void Cleanup()
|
{
|
try
|
{
|
SimpleIoc.Default.GetInstance<InformationViewModel>()?.Cleanup();
|
}
|
catch (Exception)
|
{
|
}
|
}
|
}
|
}
|