I have 3 Window in My WPF Xaml Application.
1)MainWindow have two button. one is open a project, second button is create a new project. user can click open or create a project button. it will open my second window. In that time i need to close my mainwindow(Only show My second Window).
2) second window have two labelbox,two textbox,two button. If user enter project name in textbox field, choose the location in location field. After click the create button. That button will open the my third window(that time i need to close my second window and open the third window)--only show my second window.
3) third window have display some paragraph or something... when i close the third window i need to stop the debugging the program(shutdown the my all application). how to do it.(in my application i close the my third window. window only closed. project still running. debugging not stopped. if anyone give the idea.
If I'm reading the flow correctly, Form1 opens Form2 which opens Form3. When the user closes Form3, you want the application to exit. Your project is in WPF.
For this, do two things:
In the XAML of form 3, add a Closed event handler:
<Window x:Class="WpfTestApp.Window2"
...........
Title="Window2" Height="450" Width="800" Closed="Window_Closed">
In the handler, call Environment.Exit(0) to exit the application.
private void Window_Closed(object sender, EventArgs e)
{
Environment.Exit(0); // close all windows
}
Related
I'm adding manually a click event in main window of mainwindow.xaml. There are no faults in xaml editor and the button is visible.
When switching back to the mainwindow.xaml.cs my click event is NOT automatically added. It goes for all events. These events should be automatically added in the .cs editor along the lines of:
private void Button_Click(object sender, RoutedEventsArg e)
{
}
Any ideas, pointers?
If by "adding manually an click event" you mean manually typing in the XAML in the editor then no it does not add it for you at that point.
If IntelliSense is working for you, as you type in the Click="" text, it should popup a menu listing the already available click handlers that you can select AND at the top of that list should be a choice labelled "<New Event Handler>". If you select "<New Event Handler>" it will add it in for you at that time.
If you don't choose anything from the list but instead just type it in, it is not added. However, at that point, at least for Button controls, you can double-click the button control in the XAML Designer and it will add the click handler into the .xaml.cs code and take you to it.
This has me baffled.
I've written a popup box which consists of a WinForms UserControl hosted inside a WindowsFormsHost, which, in turn, is hosted in a Primitives.Popup which is displayed on the screen. The whole application is WPF, but this control was lifted from an earlier application written in WinForms.
The popup is activated by an external event (an incoming phone call from a CTI Server).
Inside the UserControl is a textbox control. When the user clicks in the text box, I call the Focus method on the Popup, then call the Focus method on the textbox. The textbox gets the focus. I can be fairly sure of that because the box shows a cursor after clicking in it, and also I have a "GotFocus" event handler that prints a debugging message.
However, if there was another program active at the time the incoming event occurs, any keys that are pressed on the keyboard continue to go to that program, not to the text box. Only if the user clicks in another part of my application (i.e., part of the screen outside the popup) to make it the active program, and then clicks in the text box is the text box able to receive keyboard input.
I hope I've given enough information without overwhelming you with the myriad of details. If there's something else anyone needs to point me in the right direction, I'll be happy to provide it.
Because the WinForm TextBox is hosted, setting focus on it does not activate the hosting WPF Window. Add a line to activate the Window.
private void TextBox_Click(object sender, EventArgs e)
{
this.Activate(); //activate the Window
(sender as System.Windows.Forms.TextBox).Focus();
}
I am using Application.Current.Activated to bring all windows to the front when any one is clicked. This is working great, but doesn't work when I have a modal dialog open using .ShowDialog()
Clicks on other windows of the application (besides the dialog) do not result in the application being activated. The default behavior is to do nothing. (The clicks appear to be entirely IGNORED!)
How can I make it so that when any window of the application is clicked, the open dialog is brought to the front? (The expected behavior based on how pretty much every application works)
YES: I did set the owner of the dialog to my MainWindow, and clicking on the main window produces the desired result, but clicking any other window does nothing.
Code:
Create a new WPF project and add two windows.
Then put a button on MainWindow.
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Window1 foo = new Window1();
foo.Show();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Window2 modal = new Window2();
modal.Owner = this;
modal.ShowDialog();
}
}
To see what I'm talking about, click the button to open the modal dialog.
The desired behavior is what happens when MainWindow is clicked.
I want the same to happen when Window1 is clicked.
AFAIK, a modal dialog (which .ShowDialog() triggers) blocks all other windows thereby Activation events.
As per the MSDN:
When a Window class is instantiated, it is not visible by default. ShowDialog shows the window, disables all other windows in the application, and returns only when the window is closed. This type of window is known as a modal window.
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog(v=vs.110).aspx
This may be an ugly hack, but maybe you can accomplish what you need to by creating your modal window on a separate thread thereby letting your main application continue to process activation (and other) events? You would need a way to prevent 2 of that 2nd modal dialog from opening though.
I have an application which starts with a simple start screen allowing the user to select either New or Open a project. When selecting New I have a new window displayed which is a wizard that collects data to be passed to the Main window.
I create a new Window for the Main window and show that.
Then I close the wizard easily enough with this.close();
But how do I close the initial window which is the Startup URI window?
Application.Current.MainWindow.Close();
Pass the Startup window to the main window as a constructor parameter or property, then call Close() on it.
This issue regarding WPF window (XAML application)
I have a two windows one window getting launced from another window.
Both window get into maximized state when gets open
the child window which gets open has a grid on it and we have operation (double click on row click should close the window).
Problem is happening that when we double click on grid row it closes form correctly but if accidently mouse remains in the same position then some operation on previous window gets perform. if mouse point in different location then there is no problem.
I am not able to define this as event bubbling in WPF or routed events.
Could you please advise on this.
I think you should add:
e.Handled = true