• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3750
  • Last Modified:

How to close parent window from user control in WPF?

This is a WPF application:

I have to implement a user control, in which there are two buttons, "Add" and "Cancel".
The Add button has to open a new window, and load another user control to that window.
The Cancel button has to close this window.
The current window only load this single user control .

How do we achieve that?
1 Solution
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
hi.. try this code it is working

In user control 'login' button add this:
Window parentWindow = Window.GetWindow(this);
chuang4630Author Commented:
It works. Thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now