Reputation: 4095
I have 4 windows.
1. SubjectMovies.xaml
2. SpecificMovies.xaml
3. SearchMovies.xaml
4. VideoPlayer.xaml
All the first 3 windows can open the forth one.
I want to know which one openend the fourth when the fourth is opened and store it in variable (to use it later - I want to use it like that: Sender(as Window).Show()), something like:
Window sender;
public VideoPlayer(Window s)
{
InitializeComponent();
sender = s;
}
private void GoBack()
{
this.Hide();
sender.Show();
}
Upvotes: 0
Views: 150
Reputation: 22038
I recomment the ShowDialog on the child to achieve this, because the child should not be responsible for showing his parent.
example:
public void OpenVideoPlayer()
{
VideoPlayer vp = new VideoPlayer();
this.Hide();
vp.ShowDialog();
this.Show();
}
This way the child doesn't depend on a parent. Also if you don't want to hide the parent, but instead to minimize it, the parent is in control of that.
With events:
public void OpenVideoPlayer()
{
VideoPlayer vp = new VideoPlayer();
vp.Closed += vp_Closed;
this.Hide();
vp.Show();
}
void wnd_Closed(object sender, EventArgs e)
{
this.Show();
}
Upvotes: 0
Reputation: 6547
You want to set the Owner
property of the VideoPlayer
window.
from each window you are opening it:
VideoPlayer vp = new VideoPlayer();
vp.Owner = this;
Inside VideoPlayer
you can access it by this.Owner
.
No need to recieve it as a parameter in the constructor.
Upvotes: 2