wpf实现仿qq消息提示框

原文: wpf实现仿qq消息提示框

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huangli321456/article/details/50523144

1、实现步骤

1.1 另起一个窗口作为消息提示的窗口,在主窗体中调用,先处理一下消息框的展示问题, AllowsTransparency="True"  WindowStyle="None" WindowStartupLocation="Manual",实现允许透明,隐藏自带的工具条(关闭、最大/最小化),自定义窗口位置。

1.2 修改窗体的展示位置为右下角

1.3 通过渐入动画展示窗体,通过定时器自动关闭消息框,关闭时通过渐出动画关闭窗体。

2、关键代码:

渐出动画:

<Window.Resources>
        <Storyboard x:Key="ClosedStoryboard" Storyboard.TargetName="mGrid">
            <DoubleAnimation From="0" To="1" Duration="0:0:0.2" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[1].Offset"/>
            <DoubleAnimation From="0" To="1" Duration="0:0:0" BeginTime="0:0:0.2" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Offset"/>
            <ColorAnimation To="#00000000" Duration="0" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Color"/>
        </Storyboard>
        <LinearGradientBrush x:Key="ClosedBrush" StartPoint="0.5,0" EndPoint="0.5,1">
            <GradientStop Color="#FF000000" Offset="1"/>
            <GradientStop Color="#FF000000" Offset="1"/>
            <GradientStop Color="#FF000000" Offset="0"/>
        </LinearGradientBrush>
    </Window.Resources>


添加遮罩层:

<Grid.OpacityMask>
            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                <GradientStop Color="#00000000" Offset="0"/>
                <GradientStop Color="#00000000" Offset="1"/>
                <GradientStop Color="#00000000" Offset="1"/>
            </LinearGradientBrush>
        </Grid.OpacityMask>


添加触发器,窗体加载完后启动渐入动画:

<Grid.Triggers>
            <EventTrigger RoutedEvent="Window.Loaded">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation From="1" To="0" Duration="0:0:0.2" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[1].Offset"/>
                            <DoubleAnimation From="1" To="0" Duration="0:0:0" BeginTime="0:0:0.2" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Offset"/>
                            <ColorAnimation To="#FF000000" Duration="0" Storyboard.TargetProperty="OpacityMask.(GradientBrush.GradientStops)[2].Color"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </Grid.Triggers>


关闭提示框是先启动渐出动画,再关闭窗体:

this.IsEnabled = false;

            mGrid.OpacityMask = this.Resources["ClosedBrush"] as LinearGradientBrush;
            Storyboard std = this.Resources["ClosedStoryboard"] as Storyboard;
            std.Completed += delegate { this.Close(); };

            std.Begin();


源码下载

效果:


posted on 2018-09-11 16:58 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/9628822.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值