I am trying to figure out WPF and MVVM issues, but there is a snag. This question is similar but not enough ...
I have a "login" form which is written using MVVM pattern.
This form contains a viewboard that contains user names and passwords, which are obliged to view XAML using normal data binding. It also has a "login" command, which is attached to the "Login" button on the form, using the normal database, Egan.
When a "login" command sets a fire, this view invites a function in the modell that goes off and sends data to the network to log on. When this function is complete, then there are 2 actions:
-
The login was invalid - we only show a message box and it's all OK
-
The login was valid, we have to close the login form and it must return the truth as your
DialogResult
...
Update < Make / h3> finally I violated the "purity" of Mvivim patterns and see uncovered a publish to close
event, and off
method. After that, look at the void box only . Call OFF
. The view is known through an IOC container through an interface and gets wired, so no test qualification or maintenance is lost. It seems that no one is silly on acceptable answer -5 votes! Although I have to solve the problem in a "pure" know well the good feelings, of course I'm just not one who thinks that just a line pattern in 200 lines of events, orders and practices To avoid the name of "pattern" and "purity" is a little ridiculous ....
I induced There was no style to write a simple enclosed property, no trigger ; Instead, you can just do this:
& lt; Window ... xmlns: XC = "clr- namespace: ExCastle.Wpf" XC: DialogCloser.DialogResult = "{Binding DialogResult}" & gt;
It is almost clear as if the WPF team had received it properly and made the dialog a dependency asset at the first place. Just put a bool? DialogResult
implement property and INotifyPropertyChanged on your ViewModel, and saw off your ViewModel window (and its DialogResult set) can simply by setting a property. It should be like MVVM.
Here is the code for DialogClosure:
Using the system. Namespace ExCastle.Wpf {public static class DialogCloser {public static DependencyProperty DialogResultProperty = DependencyProperty.RegisterAttached ( "DialogResult", typeof (bool), typeof (DialogCloser), New PropertyMetadata (DialogResultChanged) to read only?); Private Static Wired Dialog Result Changed (Dependency Object D, DependencyProperty Change Avenger ARG E) {var Window = As D Window; If (window! = Tap) window Dialogreshant = E. Newwol's form? } Public Fixed Zero SetDialogResult (Window Target, bool? Value) {target.SetValue (DialogResultProperty, Value); }}}
I have also posted this.
Comments
Post a Comment