编辑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
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
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 }
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音乐播放器。