All that the viewmodel needs to do is get the credentials from the view, submit them to the server and give the response back to the view, which is then responsible for showing a closing animation and all that good stuff before actually closing. Return windowManager.ShowDialog(splashScreenViewModel)=true Ä«efore you kill me for using code behind, I want to say that in my opinion displaying the login dialog is view related work and the viewmodel shouldn't know anything about it. Name, AssemblyVersion, Culture, PublicKeyToken, Type. Var splashScreenViewModel = container.Resolve() Return serviceProxy.Connect(userName, password) ĪppBootstrapper.cs(The relevant part): protected override void OnStartup(object sender, e)Īpplication.ShutdownMode = Īpplication.ShutdownMode = Password = "parola123" //don't worry it's fake :D Public bool Login(string userName,string password) To make it even more complex: these Windows Managers have different interfaces and features. Public SplashScreenViewModel(ISchoolTestMakerServiceProxy serviceProxy) Caliburn.Micro Xaml made easy The Window Manager It is quite hard to write documentation for the Window Manager, as there is not one Window Manager but there is one per platform (Silverlight, Phone, WPF and WinRT). ISchoolTestMakerServiceProxy serviceProxy SplashScreenViewModel.cs: public class SplashScreenViewModel : Screen Sb.Completed += (s,e) => ((SplashScreenViewModel)this.DataContext).Trålose(dialogResult) Storyboard sb = this.FindResource("WindowClosingStoryboard") as Storyboard Private void CloseWindow(bool dialogResult) Return Task.Run(() => viewModel.Login(userName, password)) SplashScreenViewModel viewModel = (SplashScreenViewModel)this.DataContext Private Task AttemptLogin(string userName,string password) While (!(await AttemptLogin(loginDialogData.Username,loginDialogData.Password))) NegativeButtonVisibility=Visibility.Visible LoginDialogData = await this.ShowLoginAsyncĬolorScheme=MetroDialogColorScheme.Accented, : public partial class SplashScreenView : MetroWindowĪsync private void MetroWindow_Closing(object sender, e) Think of a Visual Studio splash screen when you run it for the first time. After a few seconds/loading all the data, a login dialog appears inside the splash screen, asking you to enter username and password. Instance on the other hand registers a pre-constructed instance to be registered against a type only.We are working on an application with a splash screen. The RegisterInstance method allows a pre-constructed instance to be registered with the container against a type, key or both. For now, the public definition of SimpleContainer is shown below. There are other classes which act as supporting infrastructure in the form of extension methods, which are discussed later. On top of this, there are a number of extension methods included with Caliburn.Micro that provide even more flexibility when choosing to register services. Getting Started SimpleContainer is the main class used for Dependency Injection in Caliburn.Micro. SimpleContainer provides many different ways to create service bindings based on lifecycle needs. You may refer to the Bootstrapper documentation for more information on the methods above. Public class CustomBootstrapper : BootstrapperBase Īs you can see above there are 3 methods which need to be overriden to correctly register SimpleContainer with Caliburn.Micro. The code below details how to register SimpleContainer with Caliburn.Micro. D:Gerhards PlaygroundVSNetDevelopmentLabEval. This process will inject SimpleContainer into IoC which is Caliburn.Microâs built in Service Locator. AddExportedValue(new WindowManager()) batch.Creation and ConfigurationÄ«efore adding any service bindings to SimpleContainer, it is important to remember that the container itself must be registered with Caliburn.Micro for the framework to make use of the aforementioned bindings. Public SimpleContainer () void RegisterInstance ( Type service, string key, object implementation ) void RegisterPerRequest ( Type service, string key, Type implementation ) void RegisterSingleton ( Type service, string key, Type implementation ) void RegisterHandler ( Type service, string key Func handler ) void UnregisterHandler ( Type service, string key ) object GetInstance ( Type service, string key ) IEnumerable GetAllInstances ( Type service ) void BuildUp ( object instance ) SimpleContainer CreateChildContainer () bool HasHandler ( Type service, string key ) event Action ActivatedĪs you can see above, the api is broken into service registration and retrieval with a couple of support methods and a single event.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |