I have found several similar questions, but nothing that fits perfectly.
I want my main window to show up first, and if the application can't find an application configuration file I want it to pop up a dialog box to get some necessary values from the user.
If I do anything in App.xaml etc - then obviously the main window won't be open, the same goes for if I put it in my main window's OnInitialized. If I put it in OnActivated, it seems to work, but when I close the dialog or somehow click on the main window it pops up another copy of the dialog. I could put a bool in my main window that indicates whether the dialog box is open already, but that just doesn't seem optimal or the best way of doing things.
Any suggestions?
Use Loaded instead.
Related
I have a login prompt as part of a WPF application - when the user enters an incorrect password, a new modal dialog window appears informing them that their password is incorrect.
This modal dialog is launched via ShowDialog(), and behaves as expected - the dialog launches successfully, appears in front of the login prompt that spawned it (I've verified in the debugger that Owner is being set correctly to the login prompt), and the user can't click back to the login dialog until the warning message is addressed.
As part of an external requirement, we have an alternate launcher executable that sets the UIaccess attribute in the manifest file to true. I personally dislike this behavior, but due to business requirements, it cannot be removed. Other than the manifest file difference, the regular launcher and this alternate version run the exact same code, the same dlls, etc.
Here's the issue: on this UIaccess version, when the user enters the wrong password, the dialog warning of invalid credentials shows up behind the login dialog box. Then the user is unable to interact with any part of the application, because the code is still waiting for ShowDialog() to resolve, and the login dialog window is disabled until the user closes the warning prompt (hidden behind the login dialog - inaccessible).
While we were able to resolve this issue by adding a check to the constructor of the modal dialog box that looks like this (the login dialog is always set to Topmost=true, this condition ensures that other dialog boxes of the same type aren't necessarily Topmost):
if (owner != null && owner.Topmost)
Topmost = true;
We're still noticing some behavior that is different between the two versions, but only in the way this login dialog and its modal prompt are displayed - now the modal window appears on top as desired, but the user can click the login dialog and it will move up to the top, though it's still disabled.
The root of the question is: why does the UIAccess attribute change the behavior of ShowDialog() in this way? If both the dialog and the modal window are in the same thread, why should their relative positions be changed by setting UIAccess for the whole application?
Its's strange that UI Access affects the behavior of the modal dialog. Anyway I think only someone from Microsoft can give a direct answer on that. A workaround would be to implement your own custom dialog inheriting from Window where you can react on any changes in position or size. In example if the windowState chages to minimizied you could bring it back by changing state to normal and calling window.Activate(). This would immediately bring it back to TOP.
The custom message box control I implemented for our need was unminimizable Fullscreen window (inherited from Window). I made the background transparent and blured (BorderEffect) and in the middle I showed the message content, title, icon and the buttons. So if the user clicks anywhere it is a click on this window so it will not change the state. I only added IsTopMost and on SizeChanged => Maximize. This will always work. And as mentioned at the beginning this is a workaround where you can take control of your messagebox behavior. The real reason for that strange behavior (bug) is know only to microsoft and to be honest I don't think you will get any solution to your problem from them.
You can try add a new textblock in your WPF application to avoid popup dialog using to show error message,if the dialog windows is must need,you can try use a new thread to manager a new windows to show this error,and then, when this windows popup,you can disable the log in windows in your WPF application,and when get a return value from the message windows,recover it.
I have a WPF application using the ICDBurn interface to burn some data to a disk.
After calling ICDBurn::Burn a dialog is shown and the user should not be able to continue working with the application until this dialog is handled, which is not the default behaviour.
I tried passing both IntPtr.Zero as well as the applications main window handle as a parent to ICDBurn::Burn, but the result was the same.
So I want this dialog to be modal, but I would settle for setting this dialog to always on top as well.
As a first step, I figured I would need a handle to the dialog's window. I tried EnumChildWindows but did not find the dialog there.
How can I set this dialog to modal?
Edit:
based on the comment from IInspectable, I maybe passed the wrong window handle to Burn. I am using new WindowInteropHelper(Application.Current.MainWindow).Handle and I think I use no other windows in the application.
Ahh, WPF...
To get ICDBurn::Burn to correctly open as a modal dialog, it has to be called on the UI Thread (using Application.Current.MainWindow.Dispatcher).
I'm working on a program to simultaneously control a handful of other programs of the same type.
So far I use EnumWindows() and collect the handles of the appropriate windows(programs) that I'm going to be controlling. Upon recognizing some keyboard keystroke, I iterate through all of the programs(there could be any number of them open) and I post click messages to all of these programs simultaneously by using EnumChildWindows() to find the appropriate windows(buttons) based on which keystroke was pressed and then using PostMessage() to actually send the click.
Each of these programs that I'm controlling has a button named "Load Settings" which opens an Open file dialog when clicked. What I would like to do is first use PostMessage() to click "Load Settings"(I have successfully gotten this far, what follows is what I'm trying to do). Then I want to get the handle of that Open file dialog window, fill in the text field with the path to the appropriate settings file that I've already determined, then click the "Open" button to finish the task and close the Open window.
My main problem is finding that Open window. Now, I can use EnumWindows once again to find that window but the problem with this is upon clicking "Load Settings" the Open window doesn't open instantaneously. I could sleep after clicking the button, then enum through the windows to find it, but that's not practical as the window could take any amount of time to open.
I've used spy++ to gather some information about this window, but as far as I know, none of it helps enough. Anyways, here is what I have found:
The window "Open" is the Previous Window to the program which it was opened from.
The window "Open"'s parent is the program which it was opened from.
The window "Open"'s owner is the program which it was opened from.
But even though it's listed as a child of the main program under its window properties, it's listed on the same level as the main program (it's not nested like other child windows).
I've tried FindWindowEx() and EnumChildWindows() but neither could find the Open window.
I would think there should be some way to, based on some handle, get the handle of the previous window.
Once that's working, then I need to fill the Edit(text field) window with the appropriate file path.
UIA is what you want, if your goal is to automate UI actions (e.g. for testing). UIA exposes the entire UIA tree which contains all applications active on the machine.
So what you'll see is a root node which has one child node for each application. Each of those nodes should represent the top level window of that application. Any further children depend on the application itself.
See more info at UIA Overview
I am using C# and WinForms to create UI of my application.
I have main window and dialog, which is shown modal to the main window. Dialog window is not shown in task bar. I go to another application and return back by clicking at the main window task bat icon. I can see locked main window but cannot see dialog unless I select it in Alt-Tab. This is confusing for an application user.
How can I ensure showing modal window in this situation? I can see similar but unfortunately unsolved question ALT+TAB in Vista activates main window instead of previously active child window which regards to Vista (and I have Windows 7).
This is probably because you don't use the ShowDialog(owner) overload. You should fret a little bit about the exact reason that ShowDialog() cannot find an owner by itself and picked the desktop window instead. It isn't healthy. I cannot guess why from your post. See what explicitly setting the owner buys you.
Oh, this will happen when the dialog runs on its own thread. In which case ShowDialog(owner) is going to bomb.
It sounds like your dialog is not properly owned by the main window. Make sure you have assigned the main window to the dialog object's Owner property before showing the modal dialog.
I'd like to create a popup dialog box in silverlight in which i can manipulate controls, enter data, and return a value. I want it to be modal, so that when it is open, the page "Below" is inaccessible. I havent found an easy way to do this yet. Any suggestions?
I know the question asked for a Silverlight 2 solution but in Silverlight 3 (Beta now, RTW in July 2009) there is a built-in ChildWindow that can do everything you're looking for.
I haven't found a perfect solution either. The closest I have seen is this:
Using Popup to create a Dialog class
If it is ok to be non-modal, you can try this tip using HtmlPage.PopupWindow().
How to Popup a Browser Window
I'm new to the Sliverlight framework and am just starting to figure it out, but I have a similar need for a popup modal dialog box. I just tried an idea that looks promising:
I created a Rectangle (named "Shield") that covers my entire application area. It exists on top of everything in the main app. I set the fill-brush to White, and the opacity-brush to 81% so that the main app contents show through, but lightly (as in disabled). Then make sure the "Shield" is hit-testable. Now, when the "Shield" is visible, it will also, in effect, block all input to the controls below (at least from the mouse, haven't tried keyboard yet). When the app initializes, set the "Shield" visibility to Collapsed. In that state it won't block input to the main app.
The dialog box is then constructed on another canvas element that exists in the z-order on top of the shield. Normally the dialog box will be invisible, but when I need it, I just set the "Shield" to visible, and the dialog to visible. Since the dialog is on top of the "Shield" I get a very modal-like behavior. When the dialog box is closed, make both the dialog canvas and "Shield" canvas invisible again and the main app is again active.
I'm sure this the most brute-force way of doing it and that I will eventually zero in on a more elegant construct, but it works for now.
A more elegant solution is here:
http://community.devexpress.com/blogs/theonewith/archive/2008/08/06/custom-silverlight-controls-creating-a-reusable-messagebox-dialog-part-i.aspx
I had the same requirement and ScottGu's Building a Basic Modal Dialog Using a User Control was the best solution that fit my requirement.
Here's a free library that provides one: http://www.vectorlight.net/demos/popup_dialogs.aspx