Login With MVVM and WPF - Login Object must use in other windows. (Globalization) -
I am very new to WPF and MVVM patterns. I have no experience in windows too.
I have created a simple login window
_ login.axml, login vvmmdell cs
_ dashboard XML, Dashboard View Model CS
successfully after login - (we will also select language at login time)
I am displaying the username; Selected language in the dashboard window
I have written the code like this:
public partial class app: application {secure override zero start (startup eventsErgus e) {base.OnStartup ( E); Try {var login = new login (); Var loginVM = new loginview model (); Dashboard key = faucet; LoginVM.LoginCompleted + = (Sender, Args) => {Dashboard ViewModel dvModel = New Dashboard View Model (login veem); Main = new dashboard (); Main. Datacontact = dv modell; Main.ShowDialog (); Login.Hide (); }; Login.DataContext = loginVM; Login.ShowDialog (); } Hold (Exceptional) {East; }} This username and language is successfully displayed in the Dashboard window.
But my problem is the two (username and language) properties that I want to use in the dashboard to update the layout based on the language codebehind & amp; Other xaml files or other view models
Technically I want to use the Loginviewmodel object in all visual models.
I want to update the layout based on the selected language.
Note: Is this login approach good? Is there any alternative to globalization in the MVVM system?
The use of a visual model for login is completely valid. Depending on your needs, I probably would have you pass around a token system in your Lockenby. This token should be passed from your main view model (Dashboard View Model?) To the constructors of your other view models. This can be solved by using any decent IoC container.
For globalization / localization, I will use the resources (in satellite assembly) we have experimented with various things, and found that we did not like because WPF UUIDs were added when using LocBaml Are there. And the translation storage has become a database quickly becoming a display hog (even loading in bulk). It requires you to find your label etc. for a resource manager, but in my opinion, it's worth it.
For a good extension, take a look, so that you can just type:
and it will be translated using resource files.
A modified approach is just to collect the username and language is a stable property. I know that most people do not like the world, but in such a way there is very global in such a nature, And if you want so much you will be able to inject it. The downside of this approach is that your unit tests must first set this static variable.
Edit An example of a static approach: public static class RuntimeInfo {public static string user name {receives; Set; } Public stable culture; Set; }} In your loginVM, just store the required values in a stable class. This can be reached anywhere, it is not 'correct' in the form of a previous perspective, but it can be more practical than passing your username in every single view model in your application.
I still recommend injection through the IoC container.
Comments
Post a Comment