Click here to Skip to main content
12,949,700 members (72,191 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a WPF and an enter button on it, when i click enter, a new WPF is opened. But it is behind first WPF, so i used this,




but VS says "does not contain the definition"

How can i Bring that window to front.

Posted 6-Feb-13 4:21am
CHill60 6-Feb-13 10:28am
does mw2.Activate work?
Hslldm 7-Feb-13 3:35am
No but,mw2.Owner = this; solved!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

To me the question is not "How do I bring it to the front" but why did it not come to the front automatically?

The only situation in which I have seen a dialog not come to the front was when the creating window was TopMost and the dialog's Owner property had not been set.

Setting the Owner should force the dialog to the front.

Hslldm 6-Feb-13 10:55am
How can i do that?
CHill60 6-Feb-13 11:08am
mw2.Owner = this; will set the owner, but that didn't solve the problem when I tried it. mw2.TopMost = true; seems to work ... or you can remove the .TopMost = true on the first form
Hslldm 6-Feb-13 11:12am
"does not contain a definition for TopMost " gives this error
Hslldm 6-Feb-13 11:36am
mw2.Owner = this; solved! Thanks
CHill60 7-Feb-13 4:24am
aha! Didn't work for me with Windows Forms in VS2005 but clearly does work with VS2012 and WPF ... just goes to show that Microsoft *do* fix things occasionally ;-p
Alan N 7-Feb-13 4:52am
In winforms the equivalent is ShowDialog(IWin32Window owner).
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

mw2.Activate(); will attempt to bring the window to the front and focus on it.
Hslldm 6-Feb-13 10:50am
I wrote like this but didnt work.

Pete O'Hanlon 6-Feb-13 10:58am
That's because you're creating a dialog. A dialog doesn't return to the calling code until it's closed, so it won't hit the Activate. I apologise because when I read your question, for some reason, I thought you'd called Show() and not ShowDialog().

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web01 | 2.8.170524.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100