MessageBoxGuo 1.0.2.1

dotnet add package MessageBoxGuo --version 1.0.2.1
                    
NuGet\Install-Package MessageBoxGuo -Version 1.0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MessageBoxGuo" Version="1.0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MessageBoxGuo" Version="1.0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="MessageBoxGuo" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MessageBoxGuo --version 1.0.2.1
                    
#r "nuget: MessageBoxGuo, 1.0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MessageBoxGuo@1.0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MessageBoxGuo&version=1.0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=MessageBoxGuo&version=1.0.2.1
                    
Install as a Cake Tool

MessageBoxGuo

介绍

WPF信息提示气泡...

软件架构

软件架构说明 WPF .net framework

安装教程
使用说明

弹窗演示

Nuget
dotnet add package MessageBoxGuo --version 1.0.1
代码示例
<Window
    x:Class="MessageBoxGuoTests.MainWindow"
    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:local="clr-namespace:MessageBoxGuoTests"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="WPF Alert弹框示例"
    Width="800"
    Height="600"
    mc:Ignorable="d">
    <Grid>
        <StackPanel
            Width="300"
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Button
                Margin="10"
                Background="#67C23A"
                Click="SuccessButton_Click"
                Content="成功提示(局部)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#F56C6C"
                Click="ErrorButton_Click"
                Content="错误提示(局部)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#E6A23C"
                Click="WarningButton_Click"
                Content="警告提示(局部)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#909399"
                Click="InfoButton_Click"
                Content="信息提示(局部)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#409EFF"
                Click="CustomButton_Click"
                Content="自定义提示(局部)"
                Foreground="White" />

            <Separator Height="20" Margin="10" />

            <Button
                Margin="10"
                Background="#67C23A"
                Click="GlobalSuccessButton_Click"
                Content="成功提示(全局)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#F56C6C"
                Click="GlobalErrorButton_Click"
                Content="错误提示(全局)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#E6A23C"
                Click="GlobalWarningButton_Click"
                Content="警告提示(全局)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#909399"
                Click="GlobalInfoButton_Click"
                Content="信息提示(全局)"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#409EFF"
                Click="GlobalCustomButton_Click"
                Content="自定义提示(全局)"
                Foreground="White" />

            <Separator Height="20" Margin="10" />

            <Button
                Margin="10"
                Background="#FF1493"
                Click="TestMultipleAlerts_Click"
                Content="测试多个弹窗"
                Foreground="White" />
            <Button
                Margin="10"
                Background="#8A2BE2"
                Click="TestMultipleGlobalAlerts_Click"
                Content="测试多个全局弹窗"
                Foreground="White" />
        </StackPanel>

        
        <Canvas
            x:Name="AlertContainer"
            Width="300"
            Height="0"
            Margin="20"
            HorizontalAlignment="Right"
            VerticalAlignment="Top" />
    </Grid>
</Window>
using MessageBoxGuo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace MessageBoxGuoTests
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void SuccessButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.Show("操作成功!", AlertType.Success, AlertContainer);
        }

        private void ErrorButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.Show("操作失败,请重试。", AlertType.Error, AlertContainer);
        }

        private void WarningButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.Show("警告:请注意操作权限。", AlertType.Warning, AlertContainer);
        }

        private void InfoButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.Show("提示:系统将于今晚进行维护。", AlertType.Info, AlertContainer);
        }

        private void CustomButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.Show("自定义消息:这是一个自定义样式的提示框。", AlertType.Info, AlertContainer, 5000, Brushes.Purple, Brushes.White);
        }

        private void GlobalSuccessButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.ShowGlobal("全局操作成功!", AlertType.Success);
        }

        private void GlobalErrorButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.ShowGlobal("全局操作失败,请重试。", AlertType.Error);
        }

        private void GlobalWarningButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.ShowGlobal("全局警告:请注意操作权限。", AlertType.Warning);
        }

        private void GlobalInfoButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.ShowGlobal("全局提示:系统将于今晚进行维护。", AlertType.Info);
        }

        private void GlobalCustomButton_Click(object sender, RoutedEventArgs e)
        {
            AlertBox.ShowGlobal("全局自定义消息:这是一个自定义样式的提示框。", AlertType.Info, 5000, Brushes.Purple, Brushes.White);
        }

        private void TestMultipleAlerts_Click(object sender, RoutedEventArgs e)
        {
            // 测试多个弹窗
            for (int i = 1; i <= 5; i++)
            {
                int index = i;
                DispatcherTimer timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(index * 500)
                };
                timer.Tick += (s, args) =>
                {
                    timer.Stop();
                    AlertBox.Show($"测试消息 {index}", AlertType.Info, AlertContainer);
                };
                timer.Start();
            }
        }

        private void TestMultipleGlobalAlerts_Click(object sender, RoutedEventArgs e)
        {
            // 测试多个全局弹窗
            for (int i = 1; i <= 5; i++)
            {
                int index = i;
                DispatcherTimer timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(index * 500)
                };
                timer.Tick += (s, args) =>
                {
                    timer.Stop();
                    AlertBox.ShowGlobal($"全局测试消息 {index}", AlertType.Info);
                };
                timer.Start();
            }
        }
    }
}

📋 方法总览

类别 方法名 参数 说明 默认值
基础弹窗 Show message, type 基础弹窗,3秒自动关闭 时长: 3000ms
Show message, type, container 指定容器显示 时长: 3000ms
Show message, type, duration 指定显示时长 -
Show message, type, container, duration 指定容器和时长 -
样式定制 Show message, type, duration, customBackground, customForeground 自定义背景/前景色 -
Show message, type, container, duration, customBackground, customForeground 容器+自定义样式 -
分组管理 Show message, type, token 使用token分组 时长: 3000ms
Show message, type, container, token 容器+token分组 时长: 3000ms
Show message, type, duration, token 时长+token分组 -
Show message, type, container, duration, token 全参数配置 -
全局弹窗 ShowGlobal message, type 全局弹窗 时长: 3000ms
ShowGlobal message, type, duration 全局+指定时长 -
ShowGlobal message, type, duration, customBackground, customForeground 全局+自定义样式 -
ShowGlobal message, type, token 全局+token分组 时长: 3000ms
ShowGlobal message, type, duration, token 全局+时长+token -
清理操作 Clear container 清理指定容器所有弹窗 -
Clear container, token 清理指定容器特定token弹窗 -
GlobalClear - 清理全局容器所有弹窗 -
GlobalClear token 清理全局容器特定token弹窗 -
ClearAll - 清理所有弹窗 -
ClearAll token 清理所有容器特定token弹窗 -
配置方法 CleanupResources - 释放所有资源 -
SetCustomRenderer renderer 设置自定义渲染器 需初始化时配置

🎯 AlertType 枚举类型

类型 说明 适用场景
Success 成功提示 操作成功、保存成功、提交成功等
Error 错误提示 操作失败、系统错误、验证失败等
Warning 警告提示 注意事项、风险提示、确认操作等
Info 信息提示 普通信息、状态更新、提示说明等

⚡ 快速使用示例

基础用法

// 简单成功提示
AlertBox2.Show("保存成功!", AlertType.Success);

// 错误提示(5秒)
AlertBox2.Show("保存失败!", AlertType.Error, 5000);

// 在指定面板显示
AlertBox2.Show("操作完成", AlertType.Info, myPanel);

高级用法

// 自定义样式
Brush bg = new SolidBrush(Color.LightBlue);
Brush fg = new SolidBrush(Color.DarkBlue);
AlertBox2.Show("自定义消息", AlertType.Info, 4000, bg, fg);

// 分组管理
AlertBox2.Show("用户操作", AlertType.Success, "userActions");
AlertBox2.Show("系统通知", AlertType.Info, "systemNotices");

// 全局弹窗
AlertBox2.ShowGlobal("系统维护中", AlertType.Warning, 10000);

清理操作

// 清理特定容器
AlertBox2.Clear(myPanel);

// 清理特定分组
AlertBox2.ClearAll("userActions");

// 程序退出时清理资源
AlertBox2.CleanupResources();

🔧 参数说明表

参数名 类型 必需 说明
message string 显示的消息内容
type AlertType 弹窗类型(Success/Error/Warning/Info)
container Panel 指定显示容器,null时自动选择
duration int 显示时长(毫秒),默认3000
customBackground Brush 自定义背景画刷
customForeground Brush 自定义前景(文字)画刷
token string 分组标识,用于批量管理

📝 使用建议

场景 推荐方法 时长建议 类型选择
操作成功反馈 Show("操作成功", AlertType.Success) 2000-3000ms Success
错误提示 Show("操作失败", AlertType.Error, 5000) 4000-6000ms Error
重要警告 ShowGlobal("系统警告", AlertType.Warning, 8000) 6000-10000ms Warning
普通信息 Show("提示信息", AlertType.Info, container) 3000-4000ms Info
用户操作反馈 使用token分组管理 根据重要性调整 按情况选择

🛠️ 故障排除

问题现象 可能原因 解决方案
弹窗不显示 容器未正确初始化 检查容器或使用全局弹窗
样式异常 自定义画刷设置错误 检查Brush对象是否有效
内存泄漏 未调用资源清理 程序退出时调用CleanupResources()
分组清理失败 token不匹配 检查token名称一致性

查看debug下MessageBoxGuo_Logs日志记录

QQ交流群 : 891788576

参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2.1 173 11/24/2025
1.0.2 175 11/24/2025
1.0.1 191 8/20/2025

1.0.2修复部分问题 - debug