How to Create Notification Messege in Silverlight 4 ?

 

#. Creating Notification Messege in Silverlight 4 . 

Hai !! All here i created Popup Notification messege in Silverlight. This Notification messege will show after 10 sec and it will disapear after 10 sec. Every time when user refreshing the page this notification messege will show in the UI page. 
Here is the Code which i used to create this Application .... 

in Mainpage.xaml.cs page paste this line of code . 

mainpage.xaml.cs 
============== 
public partial class MainPage : UserControl 
{ 
private Popup myPopup = new Popup(); 
DispatcherTimer timer; 
public MainPage() 
{ 
InitializeComponent(); 
timer = new DispatcherTimer(); 
timer.Interval = new TimeSpan(0, 0, 10); //after 10 second, todo... 
timer.Tick += new EventHandler(popup_open); 
timer.Start(); 

} 
void popup_open(object o, EventArgs e) 
{ 

if (timer.IsEnabled) 
{ 
OpenPopup(); 
StartTimer(); 
} 
} 

void StartTimer() 
{ 
// if (!timer.IsEnabled) 
// timer = new DispatcherTimer(); 
timer.Interval = new TimeSpan(0, 0, 10); 
timer.Stop(); 
Popup popup1 = new Popup(); 
popup1.Child = new MyPopupControll(); 
popup1.IsOpen = false; 
} 

void OpenPopup() 
{ 
Popup popup1 = new Popup(); 
popup1.Child = new MyPopupControll(); 
popup1.IsOpen = true; 
//((Popup)this.Parent).IsOpen = true; 
popup1.VerticalOffset = 480; 
popup1.HorizontalOffset = 725; 
popup1.FlowDirection = System.Windows.FlowDirection.LeftToRight; 

} 
} 

And now create one Child window silverlight page. inside this child window and inside it create your own design ...

 

Add this line 

xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 

 

Now inside the MyPopupControll.xaml.cs paste this code .

MyPopupControll.xaml.cs 
================== 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using System.Windows.Threading; 
using System.Windows.Controls.Primitives; 

namespace Loading_ClientSide_Image 

public partial class MyPopupControll : ChildWindow 

DispatcherTimer timer; 

public MyPopupControll() 

InitializeComponent(); 

timer = new DispatcherTimer(); 
timer.Interval = new TimeSpan(0, 0, 10); //after 10 second, todo... 
timer.Tick += new EventHandler(popup_dispear); 
timer.Start(); 


void popup_dispear(object o, EventArgs e) 

// close popup1 
if (timer.IsEnabled) 

closePopup(); 
StopTimer(); 


void StopTimer() 

if (timer.IsEnabled) 
timer.Stop(); 


void closePopup() 

((Popup)this.Parent).IsOpen = false; 


private void button1_Click(object sender, RoutedEventArgs e) 

MessageBox.Show("Your Status Activated. Thank You !" + MessageBoxButton.OK); 


Thats all its done . Now click on F5 to run the application and enjoy it. It will show the notification messege after 10 sec. 

If anyone having any other good idea to to do it and to give in this better effects and styles for this notification messege then please share your idea here.


Hope this application will help you to all. Thanks. 

Please post your valuable comments here if you like this. 


Thanks & Regards, 
Sanjay, 

Silverlight Developer