Properly passing values between windows c# wpf without binding -
i have window window1
window1 posta= new window1(); posta.showdialog();
i proceed work variables in posta
. return resulting variables / entire method mainwindow
. know have global variables in posta
, retrieve them trough
if(posta.dialogresult()==true){ int wantedvalue = posta.varresult; // varresult being global variable of window1 };
but seems bad , inefficient approach. tried following having button in window1 called mybutton
window1 posta= new window1(); posta.mybutton.mouserightbuttondown += mybutton_rmbdown; posta.showdialog(); public void mybutton_rmbdown(object sender, mousebuttoneventargs e){ // can access mainwindow variables cant window1 variables }
would 1 kind help?
edit: without use of databinding
if follow mvvm approach, create viewmodel, invoke dialog setting it's datacontext property viewmodel query viewmodel instance after showdialog completes. dialog view bind view model via xaml
window1 posta = new window1(); var viewmodel = new mywindowviewmodel(); posta.datacontext = viewmodel; posta.mybutton.mouserightbuttondown += mybutton_rmbdown; if (posta.showdialog()) { // things result viewmodel.someproperty... }
Comments
Post a Comment