Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In WPF one can do the following:

C#
Window window = Window.GetWindow(frameworkElement);


How would one get a hold of the window in a Windows Store app, since Windows.UI.Xaml.Window doesn't have the GetWindow method.

What I have tried:

I tried looking at the MSDN documentation but didn't find a suitable method. I also tried walking up the tree of Parents, but didn't end up at the Window.
Posted
Comments
Sergey Alexandrovich Kryukov 11-Apr-16 15:11pm    
Even in WPF it's not really needed. Why?
1) First, you can always design a control type which can have this property which could be assigned to appropriate references; 2) it's generally not the best idea to pass a window reference to its controls.
If WPF, you can also traverse the Logical Tree up...

"Get hold" does not really express what really happens.

—SA
FantasticFiasco 11-Apr-16 16:35pm    
I am really biting my tongue here, but I'll try to be pleasant. Please do not assume me to be the ignorant WPF developer you most often have to deal with. After all, you replying to as many questions as you can here on CodeProject has been a occupation of yours for years. I really hope it has payed off.

Now to the topic. All your assumptions are wrong. I am not trying to get hold of the window in the control I am implementing, simply because I am not implementing a control. I have a framework, and you can register parts of the view to that framework. Those registered views are saved, but should be released when the window they belong to is closed. In WPF I can get hold of the window using the mentioned method, but no such method exists in a Windows Store app as far as I can see. That is why I am posting this question.

I wan't to leave you with something for you to remember me by, lets call it your lessons learned for today. When somebody is mentioning Window.GetWindow(frameworkElement), please don't propose traversing the logical nor visual tree. Please look at the implementation of Window.GetWindow with a decompiler of your choice and see for yourself why that solution is much better than those you propose.
Sergey Alexandrovich Kryukov 11-Apr-16 16:57pm    
Pay attention that I haven't done a single assumption. Where? And it would be very nice to explain your expression "get hold". I never assume implementation of a control, I just listed it as one of options. It's absolutely irrelevant if you actually implemented it or not.

Anyway, the question under discussion is extremely simple. Is there such method? No: https://msdn.microsoft.com/library/windows/apps/br209041#methods.

Do you need it? I doubt it. I did not propose any solutions at all, by the way. This is you who assume something.

Your idea to look at the WPF implementation is good, but why to look at something not relevant to your question? Anyway, you mentioned that you looked up the tree and failed to find the item. Listen, you failed. I have no idea why. 1) you might not have the control inserted at this moment; 2) or you looked up incorrectly. Why asking a question if you don't want to show what you have done?

Your advice to propose or not proposing something is considered, but it looks at least weird. There is a good number of cases when some need to traverse the logical tree, and sometimes even the visual tree. It was not a solution; it was the illustration.

Thank you for your concerns, but I would note that you create a storm in a glass of water, taking simple things emotionally. How, for example, you can to discussing if you are ignorant or not? Perhaps you need to feel more confident. No one suggested anything like that. Aren't you shifting trivial things to personal issues?

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900