WPF Flyout风格动画消息弹出消息提示框

WPF Flyout风格动画消息弹出消息提示框

效果如图:

XAML:

csharp 复制代码
<Window x:Class="你的名称控件.FlyoutNotication"
        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:dxi="http://schemas.devexpress.com/winfx/2008/xaml/core/internal"
        xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
        xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/core/themekeys"
        xmlns:local="clr-namespace:SMAT.Controls"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        Title="FlyoutNotication"
        Width="300"
        Height="80"
        AllowsTransparency="True"
        Background="Transparent"
        ResizeMode="NoResize"
        WindowStartupLocation="Manual"
        WindowStyle="None"
        mc:Ignorable="d">
    <Window.Resources>
        <Storyboard x:Key="Show">
            <DoubleAnimation Storyboard.TargetName="Translate"
                             Storyboard.TargetProperty="X"
                             From="310"
                             To="0"
                             Duration="0:0:0.5">
                <DoubleAnimation.EasingFunction>
                    <CubicEase EasingMode="EaseOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>
        <Storyboard x:Key="Hide">
            <DoubleAnimation Storyboard.TargetName="Translate"
                             Storyboard.TargetProperty="X"
                             To="310"
                             Duration="0:0:0.5">
                <DoubleAnimation.EasingFunction>
                    <CubicEase EasingMode="EaseOut" />
                </DoubleAnimation.EasingFunction>
            </DoubleAnimation>
        </Storyboard>
    </Window.Resources>
    <Border Background="Gray" BorderBrush="LightGray" BorderThickness="1">
        <Border.RenderTransform>
            <TransformGroup>
                <TranslateTransform x:Name="Translate" X="300" />
            </TransformGroup>
        </Border.RenderTransform>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <TextBlock x:Name="Title"
                       Margin="12,12,4,4"
                       FontSize="16"
                       FontWeight="Bold"
                       Text="标题" />

            <TextBlock x:Name="Message"
                       Grid.Row="1"
                       Margin="12,4"
                       Text="消息内容"
                       TextWrapping="Wrap" />
        </Grid>
    </Border>

</Window>

C#:

csharp 复制代码
 /// <summary>
 /// FlyoutNotication.xaml 的交互逻辑
 /// </summary>
 public partial class FlyoutNotication : Window
 {
     public FlyoutNotication()
     {
         InitializeComponent();
     }

     public static async void ShowNotication(string message, string title)
     {
         FlyoutNotication flyoutNotication = new FlyoutNotication()
         {
             Owner = Application.Current.MainWindow,
             ShowInTaskbar = false,
             Left = Application.Current.MainWindow.ActualWidth+ (Application.Current.MainWindow.WindowState == WindowState.Maximized?-20: Application.Current.MainWindow.Left) - 300,
             Top = Application.Current.MainWindow.ActualHeight + (Application.Current.MainWindow.WindowState == WindowState.Maximized ? -20 : Application.Current.MainWindow.Top) - 80,
         };

         flyoutNotication.Message.Text = message;
         flyoutNotication.Title.Text = title;
         var sbShow = flyoutNotication.FindResource("Show") as Storyboard;
         flyoutNotication.Show();
         sbShow.Begin();

         await Task.Delay(2000);
         var sbHide = flyoutNotication.FindResource("Hide") as Storyboard;
         sbHide.Completed += (s, e) => flyoutNotication.Close();
         sbHide.Begin();
     }
 }

调用控件:

csharp 复制代码
FlyoutNotication.ShowNotication("测试消息提示", "标题");
相关推荐
招风的黑耳21 小时前
Java生态圈核心组件深度解析:Spring技术栈与分布式系统实战
java·spring·wpf
lfw20191 天前
WPF 数据绑定模式详解(TwoWay、OneWay、OneTime、OneWayToSource、Default)
wpf
Magnum Lehar1 天前
3d wpf游戏引擎的导入文件功能c++的.h实现
3d·游戏引擎·wpf
FuckPatience2 天前
WPF Telerik.Windows.Controls.Data.PropertyGrid 自定义属性编辑器
wpf
almighty272 天前
C#WPF控制USB摄像头参数:曝光、白平衡等高级设置完全指南
开发语言·c#·wpf·usb相机·参数设置
军训猫猫头2 天前
12.NModbus4在C#上的部署与使用 C#例子 WPF例子
开发语言·c#·wpf
我要打打代码2 天前
在WPF项目中使用阿里图标库iconfont
wpf
拾忆,想起3 天前
Redisson 分布式锁的实现原理
java·开发语言·分布式·后端·性能优化·wpf
weixin_464078073 天前
wpf依赖注入驱动的 MVVM实现(含免费源代码demo)
wpf
beyond谚语3 天前
一、WPF入门介绍+Grid和StackPanel布局介绍+实战模拟Notepad++页面布局
wpf