Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i get the parent of user control wpf

Tags:

c#

wpf

i have a problem i make a window application and using some Some Wpf user control on my Window Form i want to close my form When I close the user Control,Cancel button how can i achive it.....means i want to get the parent of usercontrol

like image 541
Shashank Avatar asked Sep 16 '10 08:09

Shashank


People also ask

How can I find WPF controls by name?

FindName method of FrameworkElement class is used to find elements or controls by their Name properties. The FrameworkElement class is mother of all controls in WPF.

How can I access a control in WPF from another class or window?

If you want to access a control on a wpf form from another assembly you have to use the modifier attribute x:FieldModifier="public" or use the method proposed by Jean. Save this answer. Show activity on this post. This may be a slightly different answer, but let's think about why we need to pass data between forms.

How do I customize WPF controls?

Create a new WPF project and then right-click on your solution and select Add > New Item... It will open the following window. Now select Custom Control (WPF) and name it MyCustomControl. Click the Add button and you will see that two new files (Themes/Generic.

What is the difference between user control and custom control in WPF?

A customControl can be styled and templated and best suited for a situation when you are building a Control Library. On the contrary, a UserControl gives you an easy way to define reusable chunk of XAML which can be reused widely in your application and when you don't need to use it as a Control Library .


1 Answers

The parent of the UserControl you get with the Parent-property. The window you can get directly with the Window.GetWindow-method.

Window w=Window.GetWindow(this);
if(null != w){
    w.Close();
}
like image 147
HCL Avatar answered Nov 11 '22 05:11

HCL