silverlight 判断窗口打开

 

编辑NotificationControl控件,我们简单的对该控件进行美化,使其看起来更加友好,

 

 1  < UserControl  x:Class ="SilverlightOOBDemo.NotificationControl"
 2      xmlns ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3      xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml"
 4      xmlns:d ="http://schemas.microsoft.com/expression/blend/2008"
 5      xmlns:mc ="http://schemas.openxmlformats.org/markup-compatibility/2006"
 6      mc:Ignorable ="d"
 7      d:DesignHeight ="300"  d:DesignWidth ="400" >
 8      
 9       < Grid  x:Name ="LayoutRoot"  Background ="White" >
10           < Border  x:Name ="Frame"  Width ="300"  Height ="100"  Background ="LightYellow" >
11               < StackPanel  Orientation ="Vertical" >
12                   < Border  Width ="290"  Height ="24"  CornerRadius ="4"  Margin ="2,4,2,4" >
13                       < Border.Background >
14                           < LinearGradientBrush  StartPoint ="0.5,0.0"
15                          EndPoint ="0.5,1.0" >
16                               < GradientStop  Offset ="0.2"  Color ="#FF1C68A0"   />
17                               < GradientStop  Offset ="1.0"  Color ="#FF54A7E2"   />
18                           </ LinearGradientBrush >
19                       </ Border.Background >
20                       < Border.Effect >
21                           < DropShadowEffect  BlurRadius ="4"  ShadowDepth ="4"
22                          Opacity ="0.4"   />
23                       </ Border.Effect >
24                       < TextBlock  Text ="友情提示"  FontSize ="12"
25                      FontWeight ="Bold"  Foreground ="White"  Margin ="4"   />
26                   </ Border >
27                   < StackPanel  Orientation ="Horizontal" >
28                       < Image  Source ="/SilverlightOOBDemo;component/Images/Update.png"  Width ="48"  Height ="48"
29                      Stretch ="Fill"  Margin ="4"  VerticalAlignment ="Top"   />
30                       < TextBlock  Width ="240"  Text ="检测到新的音乐文件,已经更新到播放列表。小广告:我的博客http://jv9.cnblogs.com"
31                      FontSize ="11"  Foreground ="#FF202020"  TextWrapping ="Wrap"
32                      Margin ="4"   />
33                   </ StackPanel >
34               </ StackPanel >
35           </ Border >
36       </ Grid >
37  </ UserControl >
38 

 

 

然后回到OutofBrowserMainPage页面,这里,我们在“关于”按钮上,添加Click事件响应,使其被点击后,弹出Notifications窗口。

 

首先创建notifyWindow实例,

 

 1  #region  Private Members
 2          Window OOBWindow  =  Application.Current.MainWindow;
 3          NotificationWindow notifyWindow  =   null ;
 4           #endregion
 5 
 6           #region  Constructor
 7           public  OutofBrowserMainPage()
 8          {
 9              InitializeComponent();
10              notifyWindow  =   new  NotificationWindow();
11             
12            
13          }
14  #endregion

 

 

然后在Click事件中进行窗口激活:

 1           private   void  aboutBtn_Click( object  sender, RoutedEventArgs e)
 2          {
 3               if  ( null   ==  notifyWindow)
 4                  MessageBox.Show( " 通告窗口仅能运行在OOB模式下,请安装Silverlight应用到本地。 " );
 5 
 6               if  ( true   ==  App.Current.IsRunningOutOfBrowser)
 7              {
 8                   if  (notifyWindow.Visibility  ==  Visibility.Visible)
 9                      notifyWindow.Close();
10 
11                  NotificationControl myNotify  =   new  NotificationControl();
12                  notifyWindow.Width  =   300 ;
13                  notifyWindow.Height  =   100 ;
14                  notifyWindow.Content  =  myNotify;
15                  notifyWindow.Show( 10000 );
16              }
17                
18          }

 

 

在上面代码中,我们创建了一个新的Notification窗口实例,然后使用Show(毫秒),使其显示在客户端,最终显示效果如下:

 

 

今天的内容暂时到这里了,下一篇,我们将综合使用这些Silverlight OOB应用开发技巧实现一个完整应用实例, Silverlight Out of Browser音乐播放器。

 

本篇源代码下载

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值