silverlight 做一个QQ式的消息提示窗

消息提示窗英文名叫Toastnotifications,Toast是吐司的意思,就是烤面包片

起初看到这个名字挺费解,这跟吐司有什么关系,后来终于明白,老外烤吐司的时候是这么做的,把很多面包片放进吐司机里,就是专门烤吐司的面包机,待烤好以后,吐司机会把面包弹起来,此时就是弹出的提示窗口一样,这种比喻很形像

下面进入正题,直接上代码

MainPage xaml部分

<UserControl x:Class="NotifyApplication.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <Button Height="30" Width="200" Content="Display Notify Window" Click="Button_Click"/> </Grid> </UserControl>

code部分主要是一个用来调出提示框的按钮

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; namespace NotifyApplication { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { if(App.Current.IsRunningOutOfBrowser) { var notify = new NotificationWindow(); var win = new NotifyWindow { Header = {Text = "Custom Message Header"}, Description = {Text = "This is a custom description."} }; notify.Width = win.Width; notify.Height = win.Height; notify.Content = win; notify.Show(5000); } } } }

提示框是一个用户控件

<UserControl x:Class="NotifyApplication.NotifyWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Height="75" Width="300"> <Grid x:Name="LayoutRoot" Background="White"> <Border Background="#DDDDDD" BorderBrush="Black" BorderThickness="2"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="0.113*"/> <RowDefinition Height="0.306*"/> <RowDefinition Height="0.582*"/> </Grid.RowDefinitions> <Rectangle Fill="#FF747474" Stroke="White" StrokeThickness="0" Grid.ColumnSpan="2"/> <TextBlock TextWrapping="Wrap" Text="x" HorizontalAlignment="Right" Margin="0,0,5,0" Grid.Row="1" FontFamily="Verdana" FontWeight="Bold" FontSize="13"/> <TextBlock Name="Header" TextWrapping="Wrap" Text="Header Text" Grid.Row="1" FontWeight="Bold" VerticalAlignment="Bottom" FontSize="13" Margin="5,0,5,0" FontFamily="Tahoma"/> <TextBlock Name="Description" TextWrapping="Wrap" Text="Notification Text" Grid.Row="2" FontSize="11" FontFamily="Verdana" Margin="5,0,5,0"/> </Grid> </Border> </Grid> </UserControl>

用这里还没完,要设置成可在浏览器外运行

右键点silverlight 项目-->silverlight 标签页 -->Enable running application out of the browser 打上勾

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值