`

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;
        }
    }
}

 图片如下:

 

 

  • 大小: 8 KB
分享到:
评论
1 楼 revol 2010-11-17  
请问,你是如何调用LSMessage,并弹出窗口的?

相关推荐

    Silverlight消息框源码SilverlightMessageBoxes

    Silverlight消息框源码SilverlightMessageBoxes

    Silverlight消息框源码

    Silverlight消息框源码 项目描述: 简单,但是对Sliverlight开发者很实用。 很容易和现有的项目整合。 特性: --免费使用 --简单和容易扩展 --窗口包含,消息,错误,确认,文本输入,组合框输入 --提供了图标 --...

    Silverlight学习源代码

    silverlight toolkit中的主题(theme)应用、SilverLight 桌面文件夹效果源码、...模拟Office工具栏源码、Silverlight首页动画效果源码、Silverlight图片滑动源码、Silverlight拖拽特性源码、Silverlight消息框源码

    Silverlight模拟Office工具栏源码

    Silverlight模拟Office工具栏源码 Silverlight模拟Office工具栏开源项目,项目演示富文本框样式效果,可被用于自定义RichTextBox。

    Silverlight模拟Office工具栏

    有关Silverlight模拟Office工具栏,值得推荐

    Silverlight 模拟的趣味钢琴附源程序

    比较佩服作者的高超水平,使用Silverlight模拟出的一台趣味钢琴,这可是带有声音的钢琴哦,鼠标点击钢琴的某琴键会发出对应的声音,如果你懂得钢琴,你可以用它弹出一首曲子来,源代码公开,学习Silverlight的朋友...

    Silverlight实现的多图片列表框

    Silverlight实现的多图片列表框

    Silverlight模拟Windows Ribbon 2010界面源代码

    Silverlight,Windows Ribbon 2010,silverlight界面,silverlight源代码

    easysl经典silverlight框架

    easysl经典silverlight框架

    silverlight dataGrid 模拟双击一行事件

    silverlight 4 + vs 2010 + xp 实现了dataGrid双击一行响应事件,代码大不份来自网络,自己做了个Dome 免分下载

    Silverlight RichTextBox 富文本框应用

    用Silverlight 写的RichTextBox应用。实现了字体样式改变,插入链接、插入图片等常规功能。在VS2010和Silverlight4.0 下测试通过。

    silverlight中导入和导出Excel

    silverlight中导入和导出Excel的源代码

    Silverlight 2 Toolkit July 2009

    Microsoft Silverlight 是一个跨浏览器、跨平台的 .NET Framework 实现,用于获得 Web 的媒体体验和丰富交互式应用程序。以下各节说明如何使用 Silverlight 生成应用程序: Silverlight 的 .NET Framework 类库 ...

    Silverlight 基础和实践

    Microsoft Silverlight是一个跨浏览器的、跨平台的插件,为网络带来下一代基于。NET的媒体体验和丰富的交互式应用程序。Silverlight提供灵活的编程模型,并可以很方便地集成到现有的网络应用程序中。Silverlight可以...

    Silverlight视频分享点播系统

    本次项目采用Silverlight实现一个简单的个人多媒体平台,通过该平台,用户可以搜索自己喜欢的多媒体文件,在线播放(其播放质量优于Flash);... 9.Silverlight控件样式和控件模板 10.应用Blend工具进行开发

    Silverlight

    Microsoft Silverlight是一个跨浏览器的、跨平台的插件,为网络带来下一代基于.NET Framework的媒体体验和丰富的交互式应用程序。Silverlight提供灵活的编程模型,并可以很方便地集成到现有的网络应用程序中。...

    类似QQ的SilverlightPopup

    类似QQ右下角弹出消息框,效果也和QQ类似。渐变消失。

    Silverlight揭秘.pdf

    书中沿袭了《WPF揭秘》一书的创新性写作风格,通过极具参考价值的代码和许多专家提示。通俗明快而又深入实用地讲述了Silve rligt的各项关键技术。全书采用全彩印刷,代码示例和程序效果都原样重现,为我们展示了...

    Silverlight示例

    Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例Silverlight示例

Global site tag (gtag.js) - Google Analytics