How to refresh/reload a page after using method from windows? - c#

I have a page that have a button to open a popup windows like this:
//in page.xaml.cs
private void Add_Click(object sender, RoutedEventArgs e)
{
New_Window window = new New_Window ();
window .Show();
}
Then in a popup New_Window, i want to close the popup window and reload the previous page after a click method in a popup window. How do i do it ? thanks a lot.

Related

How Do I Call Another Window With Button Press?

I want to be able to press a button and have the program open up a new window and close the old one.
I have followed solutions from this link but i have never has success with any of them How do I open a second window from the first window in WPF?
Here is my work soo far:
Window editor = new Window();
editor.Show();
this.Close();
But this does nothing.
The program should open up a new window and close the old one.
The functionality you described will work just fine. The Problem there is would more likely be the function or Methode in which you call this function.
To write a Methode that would handle a Button press as you want is pretty good described here: https://www.c-sharpcorner.com/forums/c-sharp-button-click-hold-and-release.
Hopefully, this will help you otherwise just ask
here is a small Implementation if that helps:
public partial class MainWindow : Window
{
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
Window editor = new MainWindow();
editor.Show();
this.Close();
}
private void MainWindow_KeyUP(object sender, KeyEventArgs e)
{
}
public MainWindow()
{
this.KeyDown += MainWindow_KeyDown;
this.KeyUp += MainWindow_KeyUP;
}
}
You have to call the second window from the first. This is something I did for a project where it popped up a new login panel window:
private void displayLoginPanel_Click(object sender, EventArgs e)
{
LoginPanel myLogin = new LoginPanel(this);
myLogin.Show();
this.Hide();
}
I used hide() instead of close() because you can see that I am sending a reference of the parent to the child LoginPanel in order to come back later. You can replace the Hide() with Close().

WPF C# how to set the first window to be read only until I close the second one?

How to set the first window to be read only until I close the second one?
In button click i open new Window
private void Button_Click(object sender, RoutedEventArgs e)
{
window2 win2 = new window2();
win2.Show();
}
Now the first window should be read-only.
After closing the second window, the first one should have full access again

How to launch method when window got focus again in WPF?

My app is multi-window, here is quickly how it works:
In main window I have a list of items, when I click on one, it opens another window where I can modify it. When I close that window, I want main window to refresh its content. I've tried many event handlers including GotFocus() but it doesn't want to launch my method to refresh the list. Any advise?
If you want something to happen when the other window is closed, you can subscribe to its closed event. This will fire when the windows is closed.
private void Button_Click(object sender, RoutedEventArgs e)
{
var wnd = new Window1();
wnd.Closed += wnd_Closed;
wnd.Show();
}
void wnd_Closed(object sender, EventArgs e)
{
MessageBox.Show("Closed");
}

wpf application c# How to minimize/bring to front sub forms

My WPF application is a media player that has a button that launches another window to a certain location and is my webbrowser. Problem is, once i click my button to launch the browser, my 'hide' button does not hide the browser window :/, from what i researched i need to inherit button click events, take a look at the code:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
//opens a web browser if 'Web' is clicked on the WPF Media PLayer
Window1 f1 = new Window1();
f1.Show();
}
the ideas i thought would work is create a 'toggle button' like such:
private void button4_ClickWeb(object sender, RoutedEventArgs e)
{
ToggleButton tb = (ToggleButton)sender;
if ((bool)tb.IsChecked)
{
f1.Show();
//or
f1.WindowState = WindowState.Normal;
}
else
{
f1.Hide();
f1.WindowState = WindowState.Minimized;
}
}
this approach failed, and yes i tried variations and moving things around with NO success, i was told that i need to make a class of f1 to inherit button click events but i have no idea how to do that :/ any ideas?
here is how the app looks like:

XAML enable/disable view from another view

I'm a beginner and having some dicciculties with XAML.
I have a main view A, which has a button to open a pop-up-window B. When this happens, Window A should still be visible and openened, but disabled. I've done this in code behind (maybe not the cleanest way, but the only way I know how). The code i used for this is the following:
//Code behind from view A
private void X-Button_Click(object sender, RoutedEventArgs e)
{
var BWindow = new BView();
BWindow.Show();
this.IsEnabled = false;
}
I would like to get window A enabled again once i close window B, but i can t seem to get this work. Any help would be very much appreciated.
You could do it in the following way.
You register yourself on the Closed event of the window, and when it gets closed, you unregister the event, and re-enable the this form.
private void Button_Click(object sender, RoutedEventArgs e)
{
Window BWindow = new BWindow();
BWindow.Show();
BWindow.Closed += BWindow_Closed;
this.IsEnabled = false;
}
void BWindow_Closed(object sender, EventArgs e)
{
Window win = sender as Window;
if (win != null)
{
win.Closed -= BWindow_Closed;
}
this.IsEnabled = true;
}
I assume you are looking for modal window. See similar question asked here: How do make modal dialog in WPF?
The solution is in using ShowDialog method from Window class. See here for reference:
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx
Modal window is the concept when you open new window B from the existing window A. While the B is open, the A is disabled and cannot be used. Window A become active only when the B is closed.

Categories

Resources