Tuesday, August 28, 2012

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

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.

Answers & Comments...

Answer: 1

Miyamoto

Any ideas will be appreciated.
 According to http://msdn.microsoft.com/en-us/library/dd833073(VS.95).aspx there is no property for closing the browser.
Sharker Khaleed Mahmud



Answer: 2
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:  http://forums.silverlight.net/forums/t/158315.aspx
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.


Answer: 3
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.


Answer: 4
Hi Miyamoto,

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,
Jonathan


Answer: 5
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.


Answer: 6
Hi Miyamoto,

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,
Jonathan


Answer: 7
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?


Answer: 8
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,
Jonathan


Answer: 9
Jonathan --
Thanks very much for looking into it for me. I'll wait for a future release then.


Answer: 10
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.
http://silverlight-essentials.blogspot.com/2010/02/programmatically-exit-silverlight-4-out.html



Answer: 11
Enrico --
Great solution.  Thanks very much.


Answer: 12
Hi Enrico, 

Enrico Gebauer

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,
Jonathan


Answer: 13
In Silverlight 4 you can do following.
 Application.Current.MainWindow.Close();
 The MainWindow is added in the Silverlight 4 framework.
for more information about the MainWindow see.
 http://msdn.microsoft.com/en-us/library/system.windows.application.mainwindow(v=VS.95).aspx




Answer: 14
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.


Answer: 15 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); } } }

Answer: 16
Ok thank you it works.
But when I maximize the Window, the Content isnt. Is there a possibility to fix that?



Answer: 17
Damn! , I was looking for some thing just like that simple!
Many thankx


Answer: 18
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


Answer: 19
This doesn't work in OOB SL5, not a solution.




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog