Skip to content

English Document

纵码过河山 edited this page Apr 23, 2025 · 5 revisions

Install MessageWindowWPF nuget package.

Current types

MessageBox

MessageBox

Except for the absence of the MessageBoxOptions parameter, all other features are seamlessly integrated with the original version.

Set global using to replace all Messagebox:

global using MessageBox = MessageWindowWPF.MessageBox;

Or just replace in one script:

using MessageBox = MessageWindowWPF.MessageBox; //Just add the namespace

  MessageBox.Show("Message!");
  MessageBox.Show("Message2!", "Tip", MessageBoxButton.OK, MessageBoxImage.Information);

MessageBox-richtext
If you want to display rich text, you can also just pass in the parameters:

using MessageBox = MessageWindowWPF.MessageBox; 

  List<Inline> inlines = new List<Inline>();
  inlines.Add(new Run("normal text. "));
  inlines.Add(new Run("red text.") { Foreground = Brushes.Red });
  MessageBox.Show(inlines, "Tip", MessageBoxButton.OK, MessageBoxImage.Information);

Some configurations can also be customized:

using MessageWindowWPF;
using MessageBox = MessageWindowWPF.MessageBox;

  MessageSetting.NoSystemHeader = MessageSetting.WithCornerRadius = true; //Without system title bar, and change to rounded corners
  MessageSetting.UseDarkTheme = true;//set dark or light theme. Default is light theme.
  //MessageSetting.CustomColor = new MessageSetting.CustomColorData() { WindowText = Colors.Red };//even control text, background and other color
  MessageBox.Show("Message!", "Tip", MessageBoxButton.OK, MessageBoxImage.Information);

InputBox

InputBox

Input box similar to VB's component.

using MessageWindowWPF;

  InputBox inputBox = new InputBox();
  if (inputBox.ShowDialog("Write Something:", "Title") == true)
    Console.WriteLine(inputBox.value);

Function: inputBox.ShowDialog(string message = null, string title = null, string defaultValue = null), return bool?.

Some configurations can also be customized:

using MessageWindowWPF;

  MessageSetting.NoSystemHeader = MessageSetting.WithCornerRadius = true;
  MessageSetting.UseDarkTheme = true;
  //MessageSetting.CustomColor = new MessageSetting.CustomColorData() { WindowText = Colors.Red };
  InputBox inputBox = new InputBox();
  if (inputBox.ShowDialog("Write Something:", "Title") == true)
    Console.WriteLine(inputBox.value);

Prompt

Prompt

Fade-in and fade-out cues, support countdown and double click to close.

using MessageWindowWPF;

  Prompt.Show("Show text");

Function: Prompt.Show(string content, double liveSeconds = 3, Window owner = null, Point? point = null, Color? backColor = null), return Window.
When the parameter value of "liveSeconds" <= 0, the window will be displayed until it is closed by double-clicking.

Prompt-richtext
If you want to display rich text, you can also just pass in the parameters:

using MessageWindowWPF;

  List<Inline> inlines = new List<Inline>();
  inlines.Add(new Run("normal text. "));
  inlines.Add(new Run("red text.") { Foreground = Brushes.Red });
  Prompt.Show(inlines);

Custom configurations only have an effect on the color, but the color parameter of the function has a higher priority:

using MessageWindowWPF;
  MessageSetting.UseDarkTheme = true;
  MessageSetting.CustomColor = new MessageSetting.CustomColorData() { WindowText = Colors.Red };
  Prompt.Show("Show text");

Toast

Toast-long
Notification in the bottom right corner of the desktop, imitating the default notification of the Windows system. (Due to Microsoft's official UWP package forcing the specification of Windows version and causing issues with publishing a single exe, I implemented this notification on my own)

using MessageWindowWPF;

new ToastWindowBuilder()
    .SetTitle("Application name")
    .SetIcon(new Uri("/Resources/logo.png", UriKind.RelativeOrAbsolute))
    .SetHeader("Notification prompt title")
    .AddContent("Notification Details")
    .Show();

The ToastWindowBuilder support following setting:

  • SetTime(string time):create time string
  • SetIcon(Uri uri):application icon
  • SetTitle(string text):application name
  • SetLargeIcon(Uri uri, bool isCircle = false):large icon
  • SetHeader(string text):Notification title
  • AddContent(string text):Notification Details, each item represents a line
  • SetHeadImage(Uri uri):image which displayed above the title
  • SetBodyImage(Uri uri):image which displayed below the content and above the button.
  • AddButton(string text, Action action):Button text and corresponding events, each button is evenly distributed in width
  • SetAudioPath(string file):Customize the path for playing sound effects
  • SetDuration(int seconds):Notification duration, default is 7 seconds. If it is less than or equal to 0, it will always be displayed until manually turned off
  • KeepDisplay():Always be displayed until manually turned off
  • Mute():Notify whether to mute
  • Show():show the toast

You can also customize some configurations:

//dark theme
MessageSetting.UseDarkTheme = true;

//The maximum number of notifications displayed simultaneously exceeds the queue waiting time. If it is less than or equal to 0, there is no limit
MessageSetting.ToastMaxCount = 3;

//Latest notification display at the bottom, contrary to the default behavior of the Windows system
MessageSetting.ToastLatestAtBottom = true;

//Allow double clicking notifications to close
MessageSetting.ToastDoubleClickClose = true;

Additional information

  • Because there are only four buttons, the current text only comes with Chinese and English. The default is displayed in the current language. Alternatively, you can set it manually by changing the value of "MessageSetting.settings.UIculture".

Clone this wiki locally