Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 596319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:09:34+00:00 2026-05-13T16:09:34+00:00

is it possible to make a ChildWindow like ChildWindow in Silverlight, but for WPF?

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:09:34+00:00Added an answer on May 13, 2026 at 4:09 pm

    This class should do what you want to do:

    public class SilverlightishPopup
    {
        private Rectangle maskRectangle = new Rectangle { Fill = new SolidColorBrush(Colors.DarkGray), Opacity = 0.0 };
    
        public FrameworkElement Parent
        {
            get;
            set;
        }
    
        public FrameworkElement Content
        {
            get;
            set;
        }
    
        public SilverlightishPopup()
        {
            Button button = new Button();
            button.Width = 100;
            button.Height = 200;
            button.Content = "I am the popup!";
    
            button.Click += delegate { Close(); };
    
            Content = button;
        }
    
        public void Show()
        {
            Grid grid = GetRootGrid();
    
            if (grid != null)
            {
                DoubleAnimation opacityAnimation = new DoubleAnimation(0.5, new Duration(TimeSpan.FromSeconds(0.5)));
    
                Storyboard opacityBoard = new Storyboard();
                opacityBoard.Children.Add(opacityAnimation);
    
                Storyboard.SetTarget(opacityAnimation, maskRectangle);
                Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(Opacity)"));
    
                opacityBoard.Completed += delegate
                {
                    ScaleTransform scaleTransform = new ScaleTransform(0.0, 0.0, Content.Width / 2.0, Content.Height / 2.0);
                    Content.RenderTransform = scaleTransform;
    
                    grid.Children.Add(Content);
    
                    Storyboard scaleBoard = new Storyboard();
    
                    DoubleAnimation scaleXAnimation = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.5));
    
                    scaleBoard.Children.Add(scaleXAnimation);
    
                    Storyboard.SetTarget(scaleXAnimation, Content);
                    Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));
    
                    DoubleAnimation scaleYAnimation = new DoubleAnimation(1.0, TimeSpan.FromSeconds(0.5));
    
                    scaleBoard.Children.Add(scaleYAnimation);
    
                    Storyboard.SetTarget(scaleYAnimation, Content);
                    Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
    
                    scaleBoard.Begin();
                };
    
                opacityBoard.Begin();
    
                grid.Children.Add(maskRectangle);
            }
        }
    
        public void Close()
        {
            Grid grid = GetRootGrid();
    
            if (grid != null)
            {
                ScaleTransform scaleTransform = new ScaleTransform(1.0, 1.0, Content.Width / 2.0, Content.Height / 2.0);
                Content.RenderTransform = scaleTransform;
    
                Storyboard scaleBoard = new Storyboard();
    
                DoubleAnimation scaleXAnimation = new DoubleAnimation(0.0, TimeSpan.FromSeconds(0.5));
    
                scaleBoard.Children.Add(scaleXAnimation);
    
                Storyboard.SetTarget(scaleXAnimation, Content);
                Storyboard.SetTargetProperty(scaleXAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleX)"));
    
                DoubleAnimation scaleYAnimation = new DoubleAnimation(0.0, TimeSpan.FromSeconds(0.5));
    
                scaleBoard.Children.Add(scaleYAnimation);
    
                Storyboard.SetTarget(scaleYAnimation, Content);
                Storyboard.SetTargetProperty(scaleYAnimation, new PropertyPath("(UIElement.RenderTransform).(ScaleTransform.ScaleY)"));
    
                scaleBoard.Completed += delegate
                {
                    DoubleAnimation opacityAnimation = new DoubleAnimation(0.5, 0.0, new Duration(TimeSpan.FromSeconds(0.5)));
    
                    Storyboard opacityBoard = new Storyboard();
                    opacityBoard.Children.Add(opacityAnimation);
    
                    Storyboard.SetTarget(opacityAnimation, maskRectangle);
                    Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("(Opacity)"));
    
                    opacityBoard.Completed += delegate
                    {
                        grid.Children.Remove(maskRectangle);
                        grid.Children.Remove(Content);
                    };
    
                    opacityBoard.Begin();
                };
    
                scaleBoard.Begin();
            }
        }
    
        private Grid GetRootGrid()
        {
            FrameworkElement root = Parent;
    
            while (root is FrameworkElement && root.Parent != null)
            {
                FrameworkElement rootElement = root as FrameworkElement;
    
                if (rootElement.Parent is FrameworkElement)
                {
                    root = rootElement.Parent as FrameworkElement;
                }
            }
    
            ContentControl contentControl = root as ContentControl;
    
            return contentControl.Content as Grid;
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How is it possible to make prototype methods in C#.Net? In JavaScript, I can
Is it possible to make a site with ASP.NET MVC Framework using .NET 2.0?
Is it possible to make it appear to a system that a key was
Is it possible to make such buttons ( http://img225.imageshack.us/img225/6452/buttonslw9.jpg ) using CSS? It should
Is it possible to make efficient queries that use the complete regular expression feature
Is it possible to make a POST request from Ruby with open-uri?
Is it possible to make the text in a TextBox unselectable without disabling the
is it possible to make nant run a publish on mvc project or a
Is it possible to make a batch file which can make a persistent change
is it possible to make beep in WinCE ? i try and i get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.