微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 4中的Notification API的使用

Silverlight 4 中的Notification 如何使用:

这个功能时针对Offline程序来使用的。提供提醒功能的。类似于MSN的好友上线提示。。。

首先创建一个Silverlight Application

打开MainPage.xaml,然后放两个Button

 

一个用来把当前Silverlight应用程序安装到本地电脑。

第二个按钮式用来测试Notification功能的。

然后就是后台Button事件的绑定。

页面加载时需要把如下几个事件委托给方法

  this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            btnInstall.Click += new RoutedEventHandler(btnInstall_Click);

            btnShowNotification.Click += new RoutedEventHandler(btnShowNotification_Click);

 

MainPage_Loaded主要是创建一个notificationWindow,设置它的高度和宽度。

安装Offline的按钮点击时通过下面代码SL程序安装到本地:

   if (!IsInstalledOutOfbrowser)

            {

                Application.Current.Install();

            }

 

安装完成后.你去点击Show Notification按钮执行如下代码

  if (IsRunningOutOfbrowser)

            {

                // create your custom notification panel

                Border border = new Border()

                {

                    Background = new SolidColorBrush(Colors.Gray),

                    Height = notificationWindow.Height,

                    Width = notificationWindow.Width,

                    Child = new TextBlock()

                    {

                        Text = "This is a Custom Notification from Silverlight 4",

                        Foreground = new SolidColorBrush(Colors.White)

                    }

                };

 

                notificationWindow.Content = border;   

                notificationWindow.Show(2000);       

 

                              

 

这里只是简单的介绍。 如何使用完全是看自己需要了。可以通过与事件结合一起使用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐