I have two questions on markup below:
<Popup>
<Button x:Name="button"/>
</Popup>
- Why does
VisualTreeHelper.GetParent(button)return null? - How can I get the parent
PopupforUIElement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the
Buttonis only added to the visual tree when the popup is being displayed.Hmm… tricky …
Edit
There is an assumption in the following that your popup is defined in the XAML of
UserControlso whilst its child may not be in the visual tree the popup primitive control is.Re-using some code I’ve posted before (I really must get me a blog).
This adds an extension method to the
DependencyObjectwhich uses theVisualTreeHelperto unify the search for objects added in the visual tree. So in the usercontrol code behind you can do this:-This will find the
Popupwhich is the parent of “button”.