We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
I was working on a Silverlight Application lately and I was in the need to open up a Popup window. and I am not talking about the regular .NET Message box. Naturally I Created a Page with some controls created a new instance of it but Saddly there was no Page.Show() method .
I know you can use the Popup Control to do a similar job (although I am not sure about the fade in and out) but I just played around and I liked what came out of it, so here is my solution to this problem.
First you will need to use the Canvas or the Grid control as the Silverlight application root. We are going to use the face that these controls use the Zindex property. For example lets use this as the control:
Now we will use the fact that in the Grid the last element we add to the grid is the top most one, so we will add the “Popup” message as a border with a button in it. We have to pay attention to two important things:
This is a simple double animation that will take the opacity from 0 to 100 and will be triggered by the click of the “Click Me” Button:
Now we will have to trigger it with the click event of the “Click Me Button”:
Pretty simple. This will make you “Popup” Fade in.
This is almost the same as the fade in animation. The storyboard is very similar:
The only thing we have to pay attention to is the fact that we have to wait untill the animation is over to change the Visibility status of the border to “Collapsed” or we will loose the fade out effect. All we have to do is subscribe to the Animation Completed event and do it there:
And that’s it! You have a Popup window in Silverlight, well sort of
Got a better idea? Let me know
Tags :AnimationFade inFade outPopupSilverlightStoryboard
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd