is it possible to make a ChildWindow like ChildWindow in Silverlight, but for WPF? I tried to adapt the Silverlight ChildWindow to WPF but ran into issues with Transformations and not being able to set the Popup’s Parent. I’m trying to make something that works simular so I do not have to add code to the XAML for popups. Any ideas?
is it possible to make a ChildWindow like ChildWindow in Silverlight, but for WPF?
Share
This class should do what you want to do:
Just set the Parent property to any Framework element in the parent window (it’ll find the Window to block it with the mask), and set the content to whatever you want to be popped up (and call the Show method when you want it to be shown, of course). You’ll have to come up with the pop-up wrapper (i.e. something with a border and a close button that calls the close method) on your own, but it shouldn’t be difficult, and obviously remove the placeholder button in the constructor (it’s just there to show you how it it will look).
The only problem with this is it will only work on windows that have their content (i.e. the thing that is named “LayoutRoot” in Silverlight) is a grid (the default when you create a new WPF/Silverlight Window/Page). I had it set to work for all panels, but it looks weird when used with a StackPanel or a DockPanel (as expected). If that doesn’t work for you, let me know and we’ll figure something out.
If you play with it, you can probably get the animation to look closer to the original pop-up (perhaps using some easing). There might also be a better way to find the root, I just came up with that method on the fly, but I think it’ll work (though again, only with a Contentcontrol with its content set to a grid).
Let me know if you have any questions/problems, and I hope this solves your problem.