How to make Exit button for Out-of-browser application


  • Greetings all,

    This sounds so simple, yet I can't find anything about it.  I want to make an Exit button in a Silverlight 4 Out-of-browser application.  When the user clicks the button, the application is to quit or close or exit.  (The same effect as if the user clicks the red X icon in the upper right-hand corner of a window.)

    Any ideas will be appreciated.

    Monday, January 25, 2010 10:02 PM


All replies

  • Any ideas will be appreciated.

     According to there is no property for closing the browser.

    Sharker Khaleed Mahmud

    Monday, January 25, 2010 11:04 PM
  • shamrat --

    Thanks for your help.  I tried your suggestion.  It doesn't work for OOB, but sort of works for In-browser.  So I've posted a new question about an Exit button for in-browser at the following link:

    If you go there, shamrat, and post your above answer, I'll mark it as Answered.  And for this post, I'll leave it unanswered, still hoping yet to find the answer for Out-of-browser.

    Thanks very much.

    Tuesday, January 26, 2010 12:13 PM
  • Still looking for a solution to this question:  How to make an Exit button for a Silverlight Out-of-browser (OOB) application.

    Any ideas will be appreciated.

    Wednesday, January 27, 2010 9:16 AM
  • Hi Miyamoto, 

    When the user clicks the button, the application is to quit or close or exit.

    Actually, OOB applications do have the same icons on the right corner of the window, just as normal application window.  Based on your description, I guess you "Quit" function is a event, which is triggered before we close the application.  For somecases, we may exit the application before we save the changes.  In this scenario, we need to cancel the operation and save the data.  However, in Silverlight 4 beta, it is not achievable.   The other day, we have sent this to our product team as a feature request.  Thanks for your post.

    Best regards,


    Monday, February 01, 2010 2:00 AM
  • Jonathan --

    Thanks for your thoughts.  I saw somewhere the post you refer to, where someone expressed the need for a cancelable Quit event.  That seems like an important need, for sure.

    Here, I'm requesting something related, but different.  I need a way to have a button on a Silverlight page that the user clicks when he/she wants to quit or exit the application.  I realize that to exit, the user could instead click the red X icon in the upper right corner of the window.  But that is not really as user-friendly as an Exit button, and in a way makes any application seem unfinished or experimental.

    In other words what I need is not an OnQuit event, but rather a Quit method.  Ideally I'd also like to be able to hide the red X icon in the upper right corner, but that is not quite as important, especially if I also had the mentioned valuable cancelable Quit event.

    Monday, February 01, 2010 9:42 AM
  • Hi Miyamoto,

    I realize that to exit, the user could instead click the red X icon in the upper right corner of the window.  But that is not really as user-friendly as an Exit button, and in a way makes any application seem unfinished or experimental.

    Get a little confused.  "Silverlight page" do you mean Silverlight hosted inside a page? If yes, there is no "Exit" button by default and your "red X icon" should be the IE window close button.  If I have misunderstood you, please correct me. 

    When Silverlight runs inside a page, we can add a fake "Exit" button. When click it, Button_Click event will be raised, we can do what we want and finally call a Javascript to exit page.

    Best regards,


    Wednesday, February 03, 2010 12:33 AM
  • Jonathan --

    Yes, the word Page has taken on many meanings in the last 15 years.  I'll clarify.  When I make a simple Silverlight OOB (out-of-browser) application using Visual Studio 2010, I ask Visual Studio to Add New Item, then choose Silverlight Page.  Let's say I name it Page2.xaml.

    By default VS2010 already made another page for me, MainPage.xaml.

    Now, here is my need:  On the page called MainPage.xaml, I want to place a large button that says Exit Application.  When the user clicks that button, I want the application to end and the entire window to close.  This is the standard behavior in most traditional Windows applications, for example in Microsoft Word or Microsoft Excel or Microsoft Access.  In any of those traditional applications, the user can, from the menu, choose File/Exit.  If he does, then not only does the application quit, but also the window closes itself.  The user doesn't have to click the small red X icon in the upper right corner. 

    That simple behavior of almost all traditional Windows applications, large and small, is what I'm looking for in my simple Silverlight OOB applications:  An Exit command that quits the application and closes the window itself.

     Sorry for the confusion.  I really appreciate your help.  Any ideas?

    Wednesday, February 03, 2010 10:40 AM
  • Hi Miyamoto,

    Got what your mean clearly and made some research.  I'm afraid that it is unachievable now.  You'd better wait for the future release.

    Best regards,


    Wednesday, February 03, 2010 9:58 PM
  • Jonathan --

    Thanks very much for looking into it for me. I'll wait for a future release then. 

    Wednesday, February 03, 2010 10:16 PM
  • Hi,

    Actually you don't have to wait for a future release. With SL4 Beta, it is already possible.

    Check out my blog post for an answer to this.


    Friday, February 19, 2010 6:28 AM
  • Enrico --

    Great solution.  Thanks very much.

    Friday, February 19, 2010 9:37 AM
  • Hi Enrico, 

    dynamic _winObject = null;
    if (ComAutomationFactory.IsAvailable) //only in Trusted OOB Mode

    _winObject = ComAutomationFactory.CreateObject("WScript.Shell");
    _winObject.Run(@"cmd /k taskkill /IM sllauncher.exe & exit", 0);

    Thanks Enrico for your great solution.

    Best regards,


    Sunday, February 21, 2010 1:55 AM
  • In Silverlight 4 you can do following.


     The MainWindow is added in the Silverlight 4 framework.

    for more information about the MainWindow see.



    • Proposed as answer by Gdbdable Wednesday, March 06, 2013 7:57 AM
    Tuesday, April 27, 2010 9:48 AM
  • amko -- I was unable to get that to work using VS 2010 Beta2. 

    In the next few days I'll be installing the release VS 2010 and will try it using that.  Thanks.

    Tuesday, April 27, 2010 12:46 PM
  • private void ExitButton_Click(object sender, RoutedEventArgs e) { if (App.Current.IsRunningOutOfBrowser) { Application.Current.MainWindow.Close(); } else { if(HtmlPage.BrowserInformation.Name=="Microsoft Internet Explorer") { HtmlPage.Window.Invoke("CloseWindow"); } else { MessageBox.Show("don't know how to exit this page from this browser" + HtmlPage.BrowserInformation.Name); } } }
    Friday, June 04, 2010 4:08 AM
  • Ok thank you it works.

    But when I maximize the Window, the Content isnt. Is there a possibility to fix that?

    Sunday, July 25, 2010 10:46 AM
  • Damn! , I was looking for some thing just like that simple!

    Many thankx

    Sunday, December 12, 2010 2:19 PM
  • dang, but you have to make a slightly different version for each browser. Silverlight is just a window in a web page on a web browser host... lots of java needed to run through each different browser and tweak conditions (full screen, browser...)

    dang... now to get started on next project now that I know how to

    end it all !

    dr K

    Sunday, December 12, 2010 11:02 PM
  • This doesn't work in OOB SL5, not a solution.

    Tuesday, August 28, 2012 12:16 PM
  • Dang; i'm back and yes, it does not work. I thought there was a graceful exit in SL5 in and out of browser.

    dr Karron (drdbkarron) on facebook and

    Thursday, January 03, 2013 7:15 AM
  •    Application.Current.MainWindow.Close();

    dr Karron (drdbkarron) on facebook and

    Wednesday, March 06, 2013 11:32 AM