views:

660

answers:

3

Or would I have to do something like create a windows form and host the xaml inside it? Trying to get as consistent a look and feel as I can. If I can only do the latter, how do I achieve that?

A: 

Try here: http://www.codeproject.com/KB/WPF/wpfmodaldialog.aspx

John Fisher
He did ask for a "truly modal" window. I don't think the article you link fits that request.
Randolpho
It does reference the window.ShowDialog() solution if the main thrust of the article isn't enough.
John Fisher
+1  A: 

You can create custom dialog boxes, and they're modal. You can host a WPF Window within it and define buttons as modal closing buttons. That seems to be the best way to do a modal window, IMO.

Randolpho
+1 for realizing a modal dialog isn't just a borderless popup which is what the web world commonly refers to nowadays.
Justin Niessner
+3  A: 

This should be what you want:

var window = new MyWindow();
var helper = new WindowInteropHelper(window);
helper.Owner = this.Handle;
window.ShowDialog();

This is the key to ensuring correct behaviour upon minimise/restore. See this blog post for more information about the method.

(If this isn't quite what you need, perhaps you could define "truly modal".)

Noldorin
Would this have a different effect than setting the Window's Owner property itself? Window.Owner takes another Window rather than a handle.
YotaXP
@YotaXP: Yes, it would, as it makes the current window an *actual Win32 owner* rather than just a WPF one. Read the end part of the blog post for more info.
Noldorin
I should have mentioned that it's being opened from a WPF window. I made the mistake of assuming since ShowDialog did not appear in the intellisense, that it was unavailable. Strangely, I cannot get the parent window to minimize with the dialog on my secondary screen, but I'm chalking this up to DisplayFusion, which acts odd with WPF apps on my system.Thank you.