WPF Displaying Windows - wpf

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

Related

WPF : Getting the sender of UserControl

I am having WPF MVVM application. I am having UserControl.
From few places in application I am calling this UserControl. User Control contains Image which show camera stream and back button.
The problem is when I click "Back" in UserControl I would like to know who called it.
Does anyone know how I can get sender?

How to close previous window when it redirects to another window in wpf mvvm using caliburn micro?

I am using caliburn micro in my project with mvvm architecure. I created on user control with a single button. when i click on the button it is redirecting to another user control. But the problem is when i redirect to another window, it is attaching to the previous window.
So, can any one help me to how to close the previous window when it redirects to another window.?
Thanks.
This is an old question, but the way I would go about solving this issue is use IoC/MEF to get a reference to the window manager, do a WindowManager.CreateWindow(NewViewModel) to open a new window, then TryClose() the old window.

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.

open new silverlight window when button click

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.

Resources