Last active
October 4, 2019 10:30
-
-
Save mrtank/98acb332e7042a12a9534405eae3989e to your computer and use it in GitHub Desktop.
This file contains 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
public static class IocKernel | |
{ | |
private static StandardKernel _kernel; | |
private static int _sendingChainDepth; | |
private static FormBase _latestViewModel; | |
public static void SendTo<T>() where T: FormBase | |
{ | |
if (_kernel == null) | |
return; | |
_sendingChainDepth++; | |
T newViewModel = _kernel.Get<T>(); | |
if (_latestViewModel == null) | |
_latestViewModel = newViewModel; | |
_sendingChainDepth--; | |
if (_sendingChainDepth != 0) | |
return; | |
Messenger.Default.Send(new SetMainViewModel { ViewModel = _latestViewModel }); | |
_latestViewModel = null; | |
} | |
... |
This file contains 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
namespace ThickClient.MainWindow | |
{ | |
using DevExpress.Mvvm; | |
using PropertyChanged; | |
using OnlineService.Login; | |
using FirstInit; | |
using Messages; | |
[ImplementPropertyChanged] | |
public class MainWindowViewModel: ViewModelBase | |
{ | |
public FormBase CurrentPageViewModel { get; set; } | |
public MainWindowViewModel() | |
{ | |
if (IsInDesignMode) | |
{ | |
LoginViewModelDTO dto = new LoginViewModelDTO | |
{ | |
DialogProvider = null, | |
OnlineServiceProvider = null, | |
DataModelsProvider = null | |
}; | |
CurrentPageViewModel = new LoginViewModel(dto); | |
} | |
Messenger.Default.Register<SetMainViewModel>(this, SetViewModel); | |
IocKernel.SendTo<FirstInitViewModel>(); | |
} | |
private void SetViewModel(SetMainViewModel viewModel) | |
{ | |
CurrentPageViewModel?.Free?.Invoke(); | |
CurrentPageViewModel = viewModel.ViewModel; | |
viewModel.ViewModel.Init?.Invoke(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment