Silverlight模拟MSN和QQ即时提示消息框

LSMessagePopup.cs:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace Longshine.SLLib.LSControl
{
    public class LSMessagePopup
    {
        /// <summary>
        /// Popup窗口
        /// </summary>
        Popup _popup;

        public LSMessagePopup()
        {
            _popup = new Popup();
        }

        /// <summary>
        /// Popup窗口内容
        /// </summary>
        public FrameworkElement Content
        {
            set { _popup.Child = value; }
            get { return _popup.Child as FrameworkElement; }
        }

        /// <summary>
        /// Popup窗口移动时间
        /// </summary>
        private int _moveDuration = 1;
        public int MoveDuration
        {
            set { _moveDuration = value; }
            get { return _moveDuration; }
        }

        /// <summary>
        /// Popup窗口停留时间
        /// </summary>
        private int _stopDuration = 4;
        public int StopDuration
        {
            set { _stopDuration = value; }
            get { return _stopDuration; }
        }

        /// <summary>
        /// Popup窗口提示
        /// </summary>
        public void Alert()
        {
            double h = Application.Current.Host.Content.ActualHeight;
            double w = Application.Current.Host.Content.ActualWidth;

            _popup.HorizontalOffset = w - Content.Width;

            Storyboard storybord = new Storyboard();
            DoubleAnimationUsingKeyFrames _new_anim = new DoubleAnimationUsingKeyFrames();
            EasingDoubleKeyFrame _frame1 = new EasingDoubleKeyFrame();
            _frame1.Value = h;
            _frame1.KeyTime = new TimeSpan(0, 0, 0, 0);
            EasingDoubleKeyFrame _frame2 = new EasingDoubleKeyFrame();
            _frame2.Value = h - Content.Height;
            _frame2.KeyTime = new TimeSpan(0, 0, 0, MoveDuration);
            EasingDoubleKeyFrame _frame3 = new EasingDoubleKeyFrame();
            _frame3.Value = h - Content.Height;
            _frame3.KeyTime = new TimeSpan(0, 0, 0, MoveDuration + StopDuration);
            EasingDoubleKeyFrame _frame4 = new EasingDoubleKeyFrame();
            _frame4.Value = h;
            _frame4.KeyTime = new TimeSpan(0, 0, 0, MoveDuration + StopDuration + MoveDuration);

            _new_anim.KeyFrames.Add(_frame1);
            _new_anim.KeyFrames.Add(_frame2);
            _new_anim.KeyFrames.Add(_frame3);
            _new_anim.KeyFrames.Add(_frame4);

            storybord.Children.Add(_new_anim);

            Storyboard.SetTarget(_new_anim, _popup);
            Storyboard.SetTargetProperty(_new_anim, new PropertyPath("VerticalOffset"));
            storybord.AutoReverse = false;
            storybord.Begin();

            _popup.IsOpen = true; 
        }
    }
}

 LSMessage.xaml:

<UserControl x:Class="Longshine.SLLib.LSControl.LSMessage"
    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"
    Width="400" Height="100">
    <Grid x:Name="LayoutRoot" Background="White">
        <Border BorderThickness="1" BorderBrush="Black">
            <Grid x:Name="ucGrid" Background="Beige">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <TextBlock Margin="5" Text="是否处理这些消息?" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"/>
                <Button Width="60" Height="30" Content="Yes" Click="btnYes_Click" Grid.Column="0" Grid.Row="1"/>
                <Button Width="60" Height="30" Content="No" Click="btnNo_Click" Grid.Column="1" Grid.Row="1"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>

 LSMessage.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;

namespace Longshine.SLLib.LSControl
{
    public partial class LSMessage : UserControl
    {
        public LSMessage()
        {
            InitializeComponent();
        }

        private void btnYes_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        private void btnNo_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }
    }
}

 图片如下:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值