none
How i can show(dialog) window with animation??

    Question

  •  

    Hello all!


    Help me, please!


    I am developing an WPF Application  (3.5).
    How can I open(show) a window using animation?

    For example:

     

    Code Snippet

                Window1 window = new Window1();

     

                window.WindowStyle = WindowStyle.None;
                window.AllowsTransparency = true;

     

                DoubleAnimation animFadeIn = new DoubleAnimation();
                animFadeIn.From = 0;
                animFadeIn.To = 1;
                animFadeIn.Duration = new Duration(TimeSpan.FromSeconds(0.5));

     

                window.Show(); // Animation works!!
                window.ShowDialog(); // Animation does not work!!! :(

     

                window.BeginAnimation(Window.OpacityProperty, animFadeIn);

     

     

     

    I need to use the window as Modal (like ShowDialog() ).
     

    It may need to use another method?
    But what?

     

     

    Wednesday, January 23, 2008 11:50 AM

Answers

  • The following code works for me:

    Code Snippet
    Window window = new Window();
    window.WindowStyle = WindowStyle.None;
    window.AllowsTransparency = true;
    window.Background = Brushes.Green;
    DoubleAnimation animFadeIn = new DoubleAnimation();
    animFadeIn.From = 0;
    animFadeIn.To = 1;
    animFadeIn.Duration = new Duration(TimeSpan.FromSeconds(2));
    window.BeginAnimation(Window.OpacityProperty, animFadeIn);
    window.ShowDialog();


    You need to put the BeginAnimation call before ShowDialog call, because ShowDialog call will start a nested message loop, which means that if you call BeginAnimation after calling ShowDialog, the BeginAnimation call be never be executed before the modal dialog is closed.

    Hope this helps

    Friday, January 25, 2008 4:48 AM
  • you could try the following:

    call ShowDialog() from your main window, and then in your pop-up window set a event that fires back to you main window when the pop-up window has loaded.  then, in that main window handler you can do everything that you would like with the pop-up window while still in the scope of your main window.  if there is other work that you would like to do at the same time in the background (non-UI work) you can do that fairly effectively with a BackgroundWorker.  when you are finished with the pop-up window calling its Close() method will return you back to where you called ShowDialog().

     

    hope this helps, not sure if this is quite what you're looking for but it seems to be an effective way to load a pop-up window with animation using ShowDialog().

    Friday, January 25, 2008 6:29 AM

All replies

  • Try applying the animation to the content of the window (i.e. the xaml) instead of the window itself.

     

    Tom

     

     

    Wednesday, January 23, 2008 8:01 PM
  • I agree that perhaps this decision.

    But I would like to make pop-ups such as Windows Media Center (Vista).
     
     
     
    Windows Media Center
    Wednesday, January 23, 2008 9:55 PM
  • I tried some code that I thought would work, but I got the same problem you mentioned... works with Show(), but not ShowDialog().  You may need to use Show (or the PopUp control) and mimick the modal behavior.

     

    Tom

     

    Wednesday, January 23, 2008 10:44 PM
  •  

    I tried Popup.
    I found a critical flaw: 
    Popup not tied to the window application, with the main window handling, popup does not react, Popup remains in the old place.   Popup is not the parent window!
     
    How do the same in Windows Media? 
    Any ideas?
    maybe some layer?
    Wednesday, January 23, 2008 11:39 PM
  •  

    By the way, Tom, thank you for activity
    Wednesday, January 23, 2008 11:44 PM
  • A few thoughts:

     

    1. You can still use popup and handle window events from the main window to make the popup behave like a child.  In addition you will need to simulate the modal behavior.

     

    2. You can use a window and open it with show() instead of showDialog() and simulate the modal behavior

     

    3. Another way is to create a transparent grid, size it to the size of the main window put a transparent canvas in it and then on the canvas put the xaml that looks like the dialog.  The transparent grid/canvas prevents the user from clicking on the interface below and then you can animate the dialog looking xaml with normal wpf code.

     

    You can use #3 to simulate modal behavior for #1 or #2.

     

    Tom

     

    Thursday, January 24, 2008 2:57 PM
  • The following code works for me:

    Code Snippet
    Window window = new Window();
    window.WindowStyle = WindowStyle.None;
    window.AllowsTransparency = true;
    window.Background = Brushes.Green;
    DoubleAnimation animFadeIn = new DoubleAnimation();
    animFadeIn.From = 0;
    animFadeIn.To = 1;
    animFadeIn.Duration = new Duration(TimeSpan.FromSeconds(2));
    window.BeginAnimation(Window.OpacityProperty, animFadeIn);
    window.ShowDialog();


    You need to put the BeginAnimation call before ShowDialog call, because ShowDialog call will start a nested message loop, which means that if you call BeginAnimation after calling ShowDialog, the BeginAnimation call be never be executed before the modal dialog is closed.

    Hope this helps

    Friday, January 25, 2008 4:48 AM
  • you could try the following:

    call ShowDialog() from your main window, and then in your pop-up window set a event that fires back to you main window when the pop-up window has loaded.  then, in that main window handler you can do everything that you would like with the pop-up window while still in the scope of your main window.  if there is other work that you would like to do at the same time in the background (non-UI work) you can do that fairly effectively with a BackgroundWorker.  when you are finished with the pop-up window calling its Close() method will return you back to where you called ShowDialog().

     

    hope this helps, not sure if this is quite what you're looking for but it seems to be an effective way to load a pop-up window with animation using ShowDialog().

    Friday, January 25, 2008 6:29 AM
  • Also like Marco said make sure that you begin your initial animation either before the ShowDialog() call or somewhere like in the pop-up window's loaded event handler.

     

    Friday, January 25, 2008 6:31 AM
  •  Marco Zhou - MSFT wrote:

    You need to put the BeginAnimation call before ShowDialog call

     

     

    This ingeniously!  
    Many thanks!!!
     
    I began to realize, through CanvasZ-Order.
    Now try both options.

    Later write results.
    Friday, January 25, 2008 11:32 AM