open new silverlight window when button click - silverlight

I created a Silverlight window and I want it to appear when I press a button. How can
I do that? It doesn't has a "show" method...

To open a new address in a new window use:-
HtmlPage.Window.Navigate(new Uri("the address here"), "_blank");

see:
Silverlight Simplified MVVM Modal Popup
http://www.codeproject.com/KB/silverlight/MVVMPopUp.aspx

If you want to browse to a new silverlight application hosted in another html page you should use the NavigationService class to accomplish that.
If you on the other hand want to display another view defined in your silverlight application then you should do something like this Silverlight 3 Navigation.

Related

WPF Displaying Windows

I have been looking for a good tutorial on WPF, MVVM and windows navigation. I am trying to display a new window once a user clicks an "ok" button. Does anyone know how to go about doing this?
To display a new window using an OK button, you need to create a new instance of the window and call it's Show() method. You can either do this in the button click event (code behind) or bind it to a custom Command object (MVVM). Here's the code to open a window.
var window = new MainWindow();
window.Show();
In MVVM, some developers choose to just have 1 Window, usually MainWindow, and separate parts of their UI into UserControls. They use DataTemplates to define which UserControl appears in the MainWindow.
There are a lot of tutorials on MVVM if you just take time to Google this topic. Here's a few links that have helped me a lot.
http://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

How to Open modal window/dialog in XBAP Application?

In WPF, if i want to open a modal/response window then i write code like
Window1 _windowObj1 = new Window1();
_windowObj1.Owner = mainWindowObject;
_window1Obj.ShowDialog();
How to do the same in XBAP. I tried it, but the window is opened independently from the parent page as i cant assign it as a Owner of modal window.
How to Open modal window/dialog in XBAP Application?
I'm not really experienced with XBAP apps, but I believe you should try displaying "popups" in an adorner layer. This has the same effect (you can't access the rest of the application), but doesn't actually open another window according to windows. Google for "wpf adorner dialog" and you should get some results.
Here are some links:
How do I make modal dialog for a Page in my WPF-application?
http://www.codeproject.com/KB/silverlight/slmodal.aspx
http://www.codeproject.com/KB/WPF/wpfmodaldialog.aspx
You did implement Window of WPF? If so, it will not work in XBAP. Please host your UserControl to Windows.Form, then you can open modal window/dialog in XBAP Application

Silverlight App inside WPF WebBrowser?

I have a hopefully trivial question. Currently, my company works with a rather obscure language (SyngergyDE) and we need to call a SilverLight application inside our product. Unfortunately, this obscure 3rd party language only (currently) supports the opening of WPF screens. So with that said, I thought I'd develop a small WPF user control that contains a "WebBrowser" control and navigate to the silverlight application's URI. This works fine, and I'm able to see the SL application. Here is my question - we have a "Close" button on the SL application, and when users "Click" that button, we want the window to close.
Does anyone have any suggestions on how we can communicate the "Closing of the SL App" to the WPF user control, so that the entire WPF user control closes as well?
Thanks everyone,
-Tom
Attach an event handler to the WebBrowser.Navigated event.
Have the close button in the Silverlight application use:-
HtmlPage.Window.Navigate(new Uri("about:blank", UriKind.Absolute));
When the Navigated event fires in WPF with the url "about:blank" then its time to close the control.
Use Javascript and the HTML DOM as the glue here.
For example, when the SL app close button is clicked, have Silverlight trigger some Javascript code that sets a flag, or alternately, raises some HTML document event.
The WPF control could poll that flag in the HTML + Javascript, or alternately listen for that HTML document event, then close the user control.

Display modal Silverlight popup on HTML button click

I have the following desired workflow: on HTML button click a Silverlight modal popup (dialog) must be displayed. No Silverlight content is displayed before HTML button click and no Silverlight content must be displayed after exiting from modal SL popup.
According to our customer inclination we couldn't use another technology for such popups.
Any thoughts on how to accomplish mentioned workflow?
I'm quite new to Silverlight so all the ideas are highly appreciated.
The requirement is a little unusual, but here goes...
I am assuming you have a Silverlight test project and know enough HTML/JScript to popup a window, as you tagged this question as Silverlight only.
Think of Silverlight as just another component you can put on a web page. Any web page. It can be a small control, or fill a HTML window.
In your case you want to simply put your Silverlight startup code into a html page that a popup window can show. The popup window will be triggered by JScript attached to a button.
The Silverlight startup code is usually generated for you in a HTML test webpage in your Silverlight Webproject. Copy it from there.
If you need more detailed instructions for a specific example, please provide more detail.

how to navigate on the button click

I am developing a SilverLight Project using SilverLight BusinessApplication Template RIA services.I want to navigate from one xaml page to another xaml page on the click of a Button that is placed on the first Xaml Page. i don't want to use Hyperlink button.
Any Suggestions...
Duplicate here:
Put this inside the event handler of the button:
this.NavigationService.Navigate(new Uri("nextpage.xaml", UriKind.Relative));

Resources