Such as:
I use the MVVM pattern, but the view in the viewmodel call is less than the control, want to know how to open a new window
CodePudding user response:
You this words really let the person understand, MVVM access control and initialization in the VM for V what a window has inevitable relations, or click on the reception and trigger in the VM and initialize a form?
http://baike.baidu.com/link? Url=zY07igzY1JLInXkn2Xp3nYfA3puyRM7YwGB6fM48oJuyzC5XIzbDR5tqQ0hlWyLH6jA4kXSuPN9E9RsT7fioOq
CodePudding user response:
Instantiate the form new then show, don't want to put a contentcontrol form, inside of usercontrol and so on,
CodePudding user response:
The value can be
Such as the front desk for aView. VM for aViewModel xaml. Cs
Xaml in the written Text="Binding Text"
AView. Xaml. Wrote this. Cs datacontext=new aViewModel ();
AViewModel wrote
String text;
Public string Text
{
The get {return this. The text; }
The set {SetProperty
(ref. This text, value); } } Then only need to Text assignment in the vm CodePudding user response:
The reference 3 floor hjq624779687 response: value transfer can Such as the front desk for aView. VM for aViewModel xaml. Cs Xaml in the written Text="Binding Text" AView. Xaml. Wrote this. Cs datacontext=new aViewModel (); AViewModel wrote String text; Public string Text { The get {return this. The text; } The set {SetProperty (ref. This text, value); } } Then you just need to give the Text in the vm assignment line But I can't get in the viewmodel view object! CodePudding user response:
Quliting reference 4 floor response: Quote: reference hjq624779687 reply: 3/f The value can be Such as the front desk for aView. VM for aViewModel xaml. Cs Xaml in the written Text="Binding Text" AView. Xaml. Wrote this. Cs datacontext=new aViewModel (); AViewModel wrote String text; Public string Text { The get {return this. The text; } The set {SetProperty (ref. This text, value); } } Then you just need to give the Text in the vm assignment line But I can't get in the viewmodel view object! Why do you want to get? Events can trigger is bound to the background of entrust, entrusted can be triggered in the object, such as if it is some datasource through the binding, you can directly make xaml,,, CodePudding user response:
reference 5 floor hjq624779687 reply: Quote: refer to 4th floor quliting response: Quote: refer to the third floor hjq624779687 response: The value can be Such as the front desk for aView. VM for aViewModel xaml. Cs Xaml in the written Text="Binding Text" AView. Xaml. Wrote this. Cs datacontext=new aViewModel (); AViewModel wrote String text; Public string Text { The get {return this. The text; } The set {SetProperty (ref. This text, value); } } Then you just need to give the Text in the vm assignment line But I can't get in the viewmodel view object! Why do you want to get? Events can trigger is bound to the background of entrust, entrusted can be triggered in the object, such as if it is some datasource through the binding, you can directly make xaml,,, For example: the Login. The xaml is a Login form, if the Login is successful, so want to open a new form (Main. Xaml), at this time, I think I should open in the viewmodel, CodePudding user response:
Quote: refer to the third floor hjq624779687 response: The value can be Such as the front desk for aView. VM for aViewModel xaml. Cs Xaml in the written Text="Binding Text" AView. Xaml. Wrote this. Cs datacontext=new aViewModel (); AViewModel wrote String text; Public string Text { The get {return this. The text; } The set {SetProperty (ref. This text, value); } } Then only need to give the Text in the vm assignment line [/ You can leave a QQ or what CodePudding user response:
refer to 6th floor quliting response: Quote: refer to the fifth floor hjq624779687 reply: Quote: refer to 4th floor quliting response: Quote: refer to the third floor hjq624779687 response: The value can be Such as the front desk for aView. VM for aViewModel xaml. Cs Xaml in the written Text="Binding Text" AView. Xaml. Wrote this. Cs datacontext=new aViewModel (); AViewModel wrote String text; Public string Text { The get {return this. The text; } The set {SetProperty (ref. This text, value); } } Then you just need to give the Text in the vm assignment line But I can't get in the viewmodel view object! Why do you want to get? Events can trigger is bound to the background of entrust, entrusted can be triggered in the object, such as if it is some datasource through the binding, you can directly make xaml,,, For example: the Login. The xaml is a Login form, if the Login is successful, so want to open a new form (Main. Xaml), at this time, I think I should open in the viewmodel, As you said, can put in the Login password is bound to the background of the two constructors, then the Login button Click event can trigger is bound to the VM delegate, as long as one Click can be validated through service, if by earnestly, must entrust Hander in execution the next steps (the Main Main=new Main (), the Main, show ()) Do not have what problem CodePudding user response:
What is less than the view in the viewmodel call control??????? Since all use MVVM, so loginview always have corresponding loginviewmodel, Loginview have a login button, then loginviewmodel always has the corresponding login method? Judgement login succeeded in login to issue new one mainview shown not to go, CodePudding user response:
Said so much, really not pasted the code, be clear at a glance CodePudding user response:
The window w=new window (parameters); nullnull