Opened windows C# WPF - wpf

I have this problem:
In a C# WPF application:
I open a new Window (showOnTaskBar=true, noresize, centered);
From this opened window I open another one that is above the other opened window. The new window is without blue top bar and
showOnTaskbar=false, showDialog();
Everything is ok but if I change the focus, I mean, for example, I open Firefox or another program and then I want to go back to my
opened windows I saw just the first opened window (from step 1) the
other modal window comes up only with ALT+TAB.
So, is there a way to keep both windows always displayed ?
Code to open the second window (from the first normally opened window in step 1):
Form2 form2 = new Form2();
formA2.ShowInTaskbar = false;
form2.ShowDialog();
Thank you,
Adrian

If as I think you have said you are opening the second window from the first, I'm pretty sure you want to try setting the owner of the dialog like this:
form2.Owner = Window.GetWindow(this);
See WPF: How do I set the Owner Window of a Dialog shown by a UserControl?
Hope this helps,
Jay

Related

Rselenium close other window

When I click a input button.
It show another window.
My code like this.
Click and show other window. (the window names windowB)
OpenMEMO <- remDr$findElement(using='id', value='form1:searchListTable')
OpenMEMO$clickElement()
After doing something, I want to close windowB.
But I don't know how can I do.
I try to use
#retrieve the current window handle
currWindow <- remDr$getCurrentWindowHandle()
#retrieve the list of window handles used in the session (I have 2 windows)
windows <- remDr$getWindowHandles()
#change focus to another window (windows[[2]] is windowB)
remDr$switchToWindow(windows[[2]])
#close the current window
remDr$closeWindow()
I run remDr$closeWindow().
But it closed the original window. (Actually, I want to close windowB)
Maybe I misunderstood the usage of the code.
Please give me some suggestions.
Thanks.
Because it's intranet, I cannot provide a website link.

Open a copy of the same window using WPF

I am working with a WPF application.I have two text boxes and a button in my first window.Based on some DB operations i need to open the copy of the first window(if possible open like a new tab) provided both windows can be accessed simultaneously.I used
var MainWindow = new MainWindow();
MainWindow.ShowDialog();
and
var MainWindow = new MainWindow();
MainWindow.Show();
both of them doesnt meet my expectations.Can anyone help me.
When you use ShowDialog(), it opens a single modal dialog that is expected to be closed when complete.
If you want to open multiple windows and not block form control, try using Show() instead.
var window = new MainWindow();
window.Show();
I would advise you to read all of the relating pages on MSDN so that you can learn how everything works.
For the Show method:
Opens a window and returns without waiting for the newly opened window to close.
For the ShowDialog method:
Opens a window and returns only when the newly opened window is closed.
From the Remarks section of the Window.Show Method page:
When the Window class is instantiated, it is not visible by default. Show shows a window and returns immediately, without waiting for the window to be closed. Consequently, the opened window does not prevent users from interacting with other windows in the application. This type of window is called a modeless window. Common examples of modeless windows are properties windows, toolboxes, and palettes. To restrict a user to interacting with a specific window, the window must be opened by calling ShowDialog.
Calling Show achieves the same end result as setting Visibility property of the Window object to Visible. However, there is a difference between the two from a timing perspective.
Therefore, for your solution, I would recommend that you use the Show method instead.

How to let the parent window of a child window (a.k.a. owned window) stay active with winapi?

I am writing a small C application using winapi. There I've got a window with a child window (toolbox). I am able to keep it inside this window and so on, but my question is: How to keep the main window active, if the child window gets focused?
The main window gets grayed out in this moment.
The windows get created by:
hMainWindow = DialogBoxParam(.......);
hChildWindow = CreateDialogParam(..., hMainWindow, ...);
ShowWindow (hChildWindow, SW_SHOW);
Here a little image of the behaviour of the two windows:
I've found out that simply creating it as WS_CHILD and explicitly NOT as WS_POPUP solves that. It also turns the absolute window coordinates to relative ones so that I dont have to care about the window position anymore by moving the parent window.
// Solved
Create the child window as a modeless dialog box instead of a modal one. So instead of using DialogBox, use CreateDialog
Sorry, that's just the way Windows works: one active window at a time.
You can see this in Visual Studio if you bring up Find and Replace as a tool window, you'll see that it gets activated and the main VS window goes inactive.
Trying to have them both active at the same time could confuse users and accessibility tools like screen readers.

Dialog Window for configuration in MVVM

i'm relative new to MVVM. My current problem is a modular dialog which should "autostart" at the beginning.
I've followed the example of WAFs Email Client for modular dialogs. Is it right that the only important thing is to set the Owner Property of the dialog to the instance of the main window of the application (and of course show the window with ShowDialog() instead of Show()?
If you close this dialog without configuration the application will shutdown. But now, if I open the main window in visual studios designer mode the configuration dialog comes up and if I close it visual studio crashes.
This is because I call the ShowDialog() of the configuration dialog in the constructor of my main windows view model.
To avoid this i can check for DesignerProperties.IsInDesignTool Property, but this is more a workaround as good code style, right?
Do you have any suggestions? Thanks.
The problem here is that you are showing a dialog in the constructor of a class. That's something you don't want to do.
I would solve it like this:
Don't specify a StartupUri in your app.xaml but override OnStartup. There you check whether the configuration dialog should be shown or not. If it should be shown, show it and after it has closed with OK, show you main window.
Something like this:
override void OnStartup(...)
{
if(configurationNotComplete)
{
ConfigDialog cfg = new ConfigDialog();
if(!(cfg.ShowDialog() ?? false))
{
Shutdown();
return;
}
}
MainWindow window = new MainWindow();
window.Show();
}
You have another problem with your current approach: Your ViewModel shows a modal dialog. This means it knows at least about one View: That of the modal dialog. MVVM is one way: The View knows about the ViewModel, the ViewModel knows about the Model. There should be no connection in the other direction.

Here is a Question about WPF Window Control

ı'am opening a new window in a another window ,but when window1.show()' method is called,
window1 is down in the taskbar with caller window and they is grouping in that task bar,
I click the window1 but not showed the screen,is is still in the task bar...
Why might something like that ?
Unless you specify in Windows 7 that you do not wish to regroup the windows under the same icon, it is not possible per say. The only way I can think of would be to create a new application with that windows instead of opening the window itself., but that would be far fecthed.
Why do you need this ?

Resources