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("测试消息提示", "标题");
相关推荐
慧都小妮子1 天前
SciChart WPF v9.0 更新详解:矢量场图表、堆叠箱线图与 MVVM 轴同步来了
c#·.net·wpf·数据可视化·图表控件·图表
He BianGu1 天前
【笔记】WPF中 Brush 的类型、继承关系、使用方式和注意事项
笔记·wpf
FuckPatience3 天前
WPF GridView 列绑定时前端没有属性提示
wpf
界面开发小八哥3 天前
界面控件DevExpress WPF v26.1新版亮点 - 模板工具包 & MVVM功能全新升级
wpf·界面控件·devexpress·ui开发·.net 10
记忆停留w5 天前
Celery+Redis 分布式异步任务队列工程落地业务逻辑
大数据·人工智能·redis·分布式·缓存·架构·wpf
雪靡5 天前
WPF PerMonitorV2 下的跨窗口问题
c#·wpf
listening7776 天前
HarmonyOS 6.1 分布式文件服务实战:跨设备商品图片/视频秒开方案
wpf·harmonyos
Macbethad6 天前
基于WPF的半导体设备EAP控制程序架构设计与实现
wpf
国服第二切图仔7 天前
HarmonyOS APP《画伴梦工厂》开发第60篇-分布式软总线2.0——多设备协同新范式
分布式·wpf·harmonyos
精神底层7 天前
拒绝 UI 卡死!我用 CSnakes 实时拦截 Python 训练流,在 WPF 中重构了 ScottPlot 5 高性能 AI 看板
python·ui·wpf