/// <summary> /// Matches a View to the ViewModel and injects it into it. /// </summary> /// <param name="viewModel">ViewModel to which we shell match a View</param> /// <returns>View if found a match, otherwise Null</returns> public static Page MatchViewToViewModel(ImHereBaseViewModel viewModel) { if (viewModel is CommitteeViewModel) { return(GetViewInjectVm <CommitteeView>(viewModel)); } if (viewModel is CommitteeActivityViewModel) { return(GetViewInjectVm <CommitteeActivityView>(viewModel)); } if (viewModel is CommitteeBudgetViewModel) { return(GetViewInjectVm <CommitteeBudgetView>(viewModel)); } if (viewModel is CommitteeDocsViewModel) { return(GetViewInjectVm <CommitteeDocsView>(viewModel)); } if (viewModel is CommitteeManageViewModel) { return(GetViewInjectVm <CommitteeManageView>(viewModel)); } if (viewModel is ImHereMainViewModel) { return(GetViewInjectVm <ImHereMainView>(viewModel)); } if (viewModel is DonationsViewModel) { return(GetViewInjectVm <DonationsView>(viewModel)); } if (viewModel is LoginViewModel) { return(GetViewInjectVm <LoginView>(viewModel)); } if (viewModel is UsersViewModel) { return(GetViewInjectVm <UsersView>(viewModel)); } if (viewModel is SettingsViewModel) { return(GetViewInjectVm <SettingsView>(viewModel)); } return(null); }
/// <summary> /// Returns a singelton instance of the view T, which is hopefull registered, /// with the give ViewModel injected to its DataContext. or null if not a view. /// </summary> /// <typeparam name="T">View type requested</typeparam> /// <param name="viewModel">ViewMOdel to inject to T</param> /// <returns></returns> public static T GetViewInjectVm <T>(ImHereBaseViewModel viewModel) { var view = default(T); Application.Current.Dispatcher.Invoke(() => { view = (T)Activator.CreateInstance(typeof(T)); if (view is FrameworkElement) { (view as FrameworkElement).DataContext = viewModel; } else { view = default(T); } }); return(view); }
public NavigateMessage(ImHereBaseViewModel toViewModel) : base(null, ViewsLocator.MatchViewToViewModel(toViewModel)) { }