Last active
August 29, 2015 14:21
-
-
Save BrianJVarley/d3b1d8af77ba1e97e073 to your computer and use it in GitHub Desktop.
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
/* | |
In App.xaml: | |
<Application.Resources> | |
<vm:ViewModelLocator xmlns:vm="clr-namespace:LC_Points" | |
x:Key="Locator" /> | |
</Application.Resources> | |
In the View: | |
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}" | |
You can also use Blend to do all this with the tool's support. | |
See http://www.galasoft.ch/mvvm | |
*/ | |
using GalaSoft.MvvmLight; | |
using GalaSoft.MvvmLight.Ioc; | |
using LC_Points.Model; | |
using Microsoft.Practices.ServiceLocation; | |
using System.Collections; | |
namespace LC_Points.ViewModel | |
{ | |
/// <summary> | |
/// This class contains static references to all the view models in the | |
/// application and provides an entry point for the bindings. | |
/// </summary> | |
public class ViewModelLocator | |
{ | |
/// <summary> | |
/// Initializes a new instance of the ViewModelLocator class. | |
/// </summary> | |
public ViewModelLocator() | |
{ | |
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); | |
////if (ViewModelBase.IsInDesignModeStatic) | |
////{ | |
//// // Create design time view services and models | |
//// SimpleIoc.Default.Register<IDataService, DesignDataService>(); | |
////} | |
////else | |
////{ | |
//// // Create run time view services and models | |
//// SimpleIoc.Default.Register<IDataService, DataService>(); | |
////} | |
SimpleIoc.Default.Register<ScoreModel, ScoreProperty>(); | |
SimpleIoc.Default.Register<MainViewModel>(); | |
SimpleIoc.Default.Register<ScoreModel>(); | |
SimpleIoc.Default.Register<ViewSubjectGradeViewModel>(ScoreProperty); | |
} | |
public MainViewModel MainPage | |
{ | |
get | |
{ | |
return ServiceLocator.Current.GetInstance<MainViewModel>(); | |
} | |
} | |
public ViewSubjectGradeViewModel ViewSubjectGradePage | |
{ | |
get | |
{ | |
return ServiceLocator.Current.GetInstance<ViewSubjectGradeViewModel>(); | |
} | |
} | |
public IEnumerable IEnumerableProperty | |
{ | |
get { return SimpleIoc.Default.GetInstance<IEnumerable>(); } | |
} | |
public ScoreModel ScoreProperty | |
{ | |
get | |
{ | |
return ServiceLocator.Current.GetInstance<ScoreModel>(); | |
} | |
} | |
public static void Cleanup() | |
{ | |
// TODO Clear the ViewModels | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment