/* In App.xaml: 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 { /// /// This class contains static references to all the view models in the /// application and provides an entry point for the bindings. /// /// See http://www.mvvmlight.net /// /// public class ViewModelLocator { static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); if (ViewModelBase.IsInDesignModeStatic) { SimpleIoc.Default.Register(); } else { SimpleIoc.Default.Register(); } SimpleIoc.Default.Register(); SimpleIoc.Default.Register(); //SimpleIoc.Default.Register(); } /// /// Gets the Main property. /// [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(); } } public LoginViewModel Login { get => ServiceLocator.Current.GetInstance(); } public RunningViewModel Running { get => ServiceLocator.Current.GetInstance(); } public InformationViewModel Information { get => ServiceLocator.Current.GetInstance(); } /// /// Cleans up all the resources. /// public static void Cleanup() { try { SimpleIoc.Default.GetInstance()?.Cleanup(); } catch (Exception) { } } } }