wpf - Closing Settings dialog causes application to quit -


so here's setup. have standalone wpf application i've built vb. contained in application 2 windows, mainwindow , settingswindow, opens dialog , called subprocedure in mainwindow.xaml.vb on event of clicked "settings" button (i working code-behind better xaml if can it).

in settingswindow.xaml.vb, have subprocedure handling event of clicking close button in window. executes me.close(). intent close settingswindow , return focus mainwindow, instead, entire application terminates.

additionally, clicking close button in mainwindow closes mainwindow, doesn't terminate application in visual studio's debug mode, while closing settingswindow does.

when building application , running outside of visual studio (running .exe in windows), closing settingswindow returns mainwindow intended, attempting re-open settingswindow causes entire application crash.

i'm relatively new visual studio, , can post code needed. ahead of time help.

first, here `application.xaml.vb' file handling app startup:

class application      public shared initmain mainwindow = new mainwindow()      public shared sub appstart() handles me.startup         initmain.updatesettings()         initmain.show()     end sub end class 

the code above checks my.settings, works fine, calls mainwindow open.

here code in mainwindow sub calling settingswindow:

private sub settingstart() handles settingsbutton.mouseup     dim settingwin settingswindow = new settingswindow()      ' "if" blocks here check my.settings before opening window      settingwin.showdialog() end sub 

finally, here code closes settingswindow:

private sub closebuttonclick() handles closebutton.mouseup         me.close() end sub 

if need it, here application.xaml:

<application x:class="application" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" startup="appstart"> <application.resources>  </application.resources> </application> 

update:

it looks issue has fact instance of mainwindow in application.xaml.vb public shared, need able call instance other places update settings in realtime, can't change this. workarounds?

additionally, program functions outside of visual studio, no longer crashing.

you need set shutdownmode="onlastwindowclose" in application.xaml

<application x:class="application"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     startupuri="mainwindow.xaml"     shutdownmode="onlastwindowclose"         >     <application.resources>      </application.resources> </application> 

mainwindow.xaml.vb

class mainwindow       private sub buttonsetting_click(sender object, e routedeventargs) handles buttonsetting.click          dim settingwin settingwindow = new settingwindow()         dim rslt boolean = false          rslt = settingwin.showdialog()        end sub  end class 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -