c# - Using "this"(MainWindow.xaml.cs) in another Class -


i have 2 methods:

method 1(class 1):

private void bntstart_click(object sender, routedeventargs e) {     createmap gogo = new createmap();     gogo.dowork(ref this);//.xaml.cs//window } 

method 2(class 2)(different file "mainwindow.xaml.cs") :

public void dowork(ref window instance) {  } 

i use "instance", if in "mainwindow.xaml.cs" reference mainwindow.

by way not possible because of dispatcher(ui-thread), 1 allowed...or wrong !?

how can ?

you should not this

you can put mainwindow.xaml.cs:

public static mainwindow instance { get; private set;}  public mainwindow() {     instance = this; } 

or use like:

(mainwindow)application.current.mainwindow; 

however, views should totally self contained. there way better ways data/commands them (via proper use of mvvm).


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -