需求:实现全局消息提示框

一:创建全局Message

public class Message
{
private static readonly Style infoStyle = (Style)Application.Current.Resources["InfoMessage"];
private static readonly Style warningStyle = (Style)Application.Current.Resources["WarningMessage"];
private static readonly Style successStyle = (Style)Application.Current.Resources["SuccessMessage"];
private static readonly Style errorStyle = (Style)Application.Current.Resources["ErrorMessage"]; #region 全局
public static void Show(MessageType type, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
if (millisecondTimeOut <= 0)
{
isClearable = true;
} MessageWindow messageWindow = MessageWindow.GetInstance();
messageWindow.Dispatcher.VerifyAccess(); MessageCard messageCard;
switch (type)
{
default:
case MessageType.None:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable
};
break;
case MessageType.Info:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = infoStyle
};
break;
case MessageType.Warning:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = warningStyle
};
break;
case MessageType.Success:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = successStyle
};
break;
case MessageType.Error:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = errorStyle
};
break;
} messageWindow.AddMessageCard(messageCard, millisecondTimeOut);
messageWindow.Show();
} public static void Show(UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.None, element, millisecondTimeOut, isClearable);
} public static void ShowInfo(UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Info, element, millisecondTimeOut, isClearable);
} public static void ShowSuccess(UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Success, element, millisecondTimeOut, isClearable);
} public static void ShowWarning(UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Warning, element, millisecondTimeOut, isClearable);
} public static void ShowError(UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Error, element, millisecondTimeOut, isClearable);
} public static void Show(MessageType type, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(type, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void Show(string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.None, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void ShowInfo(string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Info, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void ShowSuccess(string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Success, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void ShowWarning(string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Warning, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void ShowError(string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(MessageType.Error, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
}
#endregion #region 指定容器
public static void Show(string containerIdentifier, MessageType type, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
if (!MessageContainer.Containers.ContainsKey(containerIdentifier))
{
return;
} if (millisecondTimeOut <= 0)
{
isClearable = true;
} Panel messagePanel = MessageContainer.Containers[containerIdentifier];
messagePanel.Dispatcher.VerifyAccess(); MessageCard messageCard;
switch (type)
{
default:
case MessageType.None:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable
};
break;
case MessageType.Info:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = infoStyle
};
break;
case MessageType.Warning:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = warningStyle
};
break;
case MessageType.Success:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = successStyle
};
break;
case MessageType.Error:
messageCard = new MessageCard
{
Content = element,
IsClearable = isClearable,
Style = errorStyle
};
break;
} messagePanel.Children.Add(messageCard); // 进入动画
Storyboard enterStoryboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation
{
From = 0,
To = 1,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(UIElement.OpacityProperty)); DoubleAnimation transformAnimation = new DoubleAnimation
{
From = -30,
To = Application.Current.MainWindow.Height / 2-100,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(transformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); enterStoryboard.Children.Add(opacityAnimation);
enterStoryboard.Children.Add(transformAnimation);
if (millisecondTimeOut > 0)
{
// 进入动画完成
enterStoryboard.Completed += async (sender, e) =>
{
await Task.Run(() =>
{
Thread.Sleep(millisecondTimeOut);
}); messagePanel.Children.Remove(messageCard);
}; } messageCard.BeginStoryboard(enterStoryboard);
// 退出动画
//Storyboard exitStoryboard = new Storyboard(); //DoubleAnimation exitOpacityAnimation = new DoubleAnimation
//{
// From = 1,
// To = Application.Current.MainWindow.Height / 2,
// Duration = new Duration(TimeSpan.FromMilliseconds(300)),
// EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
//};
//Storyboard.SetTargetProperty(exitOpacityAnimation, new PropertyPath(UIElement.OpacityProperty)); //DoubleAnimation exitTransformAnimation = new DoubleAnimation
//{
// From = 0,
// To = -30,
// Duration = new Duration(TimeSpan.FromMilliseconds(300)),
// EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
//};
//Storyboard.SetTargetProperty(exitTransformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); //exitStoryboard.Children.Add(exitOpacityAnimation);
//exitStoryboard.Children.Add(exitTransformAnimation); //if (millisecondTimeOut > 0)
//{
// // 进入动画完成
// enterStoryboard.Completed += async (sender, e) =>
// {
// await Task.Run(() =>
// {
// Thread.Sleep(millisecondTimeOut);
// }); // messageCard.BeginStoryboard(exitStoryboard);
// }; //} // 退出动画完成
//exitStoryboard.Completed += (sender, e) =>
//{
// messagePanel.Children.Remove(messageCard);
//}; //messageCard.BeginStoryboard(enterStoryboard);
} public static void Show(string containerIdentifier, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.None, element, millisecondTimeOut, isClearable);
} public static void ShowInfo(string containerIdentifier, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Info, element, millisecondTimeOut, isClearable);
} public static void ShowSuccess(string containerIdentifier, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Success, element, millisecondTimeOut, isClearable);
} public static void ShowWarning(string containerIdentifier, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Warning, element, millisecondTimeOut, isClearable);
} public static void ShowError(string containerIdentifier, UIElement element, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Error, element, millisecondTimeOut, isClearable);
} public static void Show(string containerIdentifier, MessageType type, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, type, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void Show(string containerIdentifier, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.None, new TextBlock { Text = message }, millisecondTimeOut, isClearable);
} public static void ShowInfo(string containerIdentifier, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Info, new TextBlock { Text = message, Foreground = new SolidColorBrush(Colors.White) }, millisecondTimeOut, isClearable);
} public static void ShowSuccess(string containerIdentifier, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Success, new TextBlock { Text = message, Foreground = new SolidColorBrush(Colors.White) }, millisecondTimeOut, isClearable);
} public static void ShowWarning(string containerIdentifier, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Warning, new TextBlock { Text = message, Foreground = new SolidColorBrush(Colors.White) }, millisecondTimeOut, isClearable);
} public static void ShowError(string containerIdentifier, string message, int millisecondTimeOut = 3000, bool isClearable = true)
{
Show(containerIdentifier, MessageType.Error, new TextBlock { Text = message, Foreground = new SolidColorBrush(Colors.White) }, millisecondTimeOut, isClearable);
}
#endregion
} public enum MessageType
{
None = 0,
Info,
Success,
Warning,
Error
}

二:创建消息提示控件

1:创建名为MessageCard资源字典与MessageCard类

  <LinearGradientBrush x:Key="GridBackGrounds1" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FF061118" Offset="0.191"/>
<GradientStop Color="#FF173A52" Offset="1"/>
</LinearGradientBrush> <Style x:Key="MessageCard" TargetType="{x:Type local:MessageCard}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="BorderBrush" Value="{StaticResource BorderGray}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="CornerRadius" Value="2.5"/>
<Setter Property="Background" Value="{DynamicResource GridBackGrounds1}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="ThemeColorBrush" Value="{DynamicResource DefaultForeground}"/>
<Setter Property="Margin" Value="2.5"/>
<Setter Property="Padding" Value="5"/>
<Setter Property="MinHeight" Value="60"/>
<Setter Property="MinWidth" Value="200"/>
<Setter Property="IsShwoIcon" Value="False"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MessageCard}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding ThemeColorBrush}"
BorderThickness="{TemplateBinding BorderThickness}" Margin="{TemplateBinding Margin}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding ThemeColorBrush}"
BorderThickness="{TemplateBinding BorderThickness}" Effect="{StaticResource AllDirectionEffect}"
Padding="{TemplateBinding Padding}" CornerRadius="{TemplateBinding CornerRadius}"
Grid.ColumnSpan="3"/> <ContentPresenter x:Name="contentPresenter" Focusable="False" Grid.Column="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="8 0"/>
<Button x:Name="clearButton" Foreground="{TemplateBinding ThemeColorBrush}"
Grid.Column="2" Style="{x:Null}" Height="20" BorderThickness="0" BorderBrush="Transparent" Background="Transparent"
local:ButtonHelper.ButtonStyle="Link" Visibility="{TemplateBinding IsClearable,Converter={StaticResource boolToVisibility}}"
Content="X"
> </Button>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <Style x:Key="WarningMessage" TargetType="{x:Type local:MessageCard}" BasedOn="{StaticResource MessageCard}">
<Setter Property="ThemeColorBrush" Value="{StaticResource WarningBrush}"/>
<Setter Property="IconType" Value="ErrorWarningFill"/>//IOC提示类型
<Setter Property="IsShwoIcon" Value="True"/> </Style> <Style x:Key="SuccessMessage" TargetType="{x:Type local:MessageCard}" BasedOn="{StaticResource MessageCard}">
<Setter Property="ThemeColorBrush" Value="{StaticResource SuccessBrush}"/>
<Setter Property="IconType" Value="CheckboxCircleFill"/>
<Setter Property="IsShwoIcon" Value="True"/> </Style> <Style x:Key="ErrorMessage" TargetType="{x:Type local:MessageCard}" BasedOn="{StaticResource MessageCard}">
<Setter Property="ThemeColorBrush" Value="{StaticResource ErrorBrush}"/>
<Setter Property="IconType" Value="CloseCircleFill"/>
<Setter Property="IsShwoIcon" Value="True"/> </Style> <Style x:Key="InfoMessage" TargetType="{x:Type local:MessageCard}" BasedOn="{StaticResource MessageCard}">
<Setter Property="ThemeColorBrush" Value="{StaticResource InfoBrush}"/>
<Setter Property="IconType" Value="InformationFill"/>
<Setter Property="IsShwoIcon" Value="True"/> </Style>
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using Zt.UI.Silver.Utils; namespace Zt.UI.Silver
{
public class MessageCard : ContentControl
{
public static readonly RoutedEvent CloseEvent; static MessageCard()
{
CloseEvent = EventManager.RegisterRoutedEvent("Close", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MessageCard));
DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageCard), new FrameworkPropertyMetadata(typeof(MessageCard)));
} #region 事件
// 关闭消息事件
public event RoutedEventHandler Close
{
add { base.AddHandler(MessageCard.CloseEvent, value); }
remove { base.RemoveHandler(MessageCard.CloseEvent, value); }
}
#endregion #region 依赖属性
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(MessageCard), new PropertyMetadata(default(CornerRadius))); public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
} public static readonly DependencyProperty ThemeColorBrushProperty =
DependencyProperty.Register("ThemeColorBrush", typeof(SolidColorBrush), typeof(MessageCard), new PropertyMetadata(default(SolidColorBrush))); public SolidColorBrush ThemeColorBrush
{
get { return (SolidColorBrush)GetValue(ThemeColorBrushProperty); }
set { SetValue(ThemeColorBrushProperty, value); }
} public static readonly DependencyProperty IconTypeProperty =
DependencyProperty.Register("IconType", typeof(IconType), typeof(MessageCard), new PropertyMetadata(default(IconType))); public IconType IconType
{
get { return (IconType)GetValue(IconTypeProperty); }
set { SetValue(IconTypeProperty, value); }
} public static readonly DependencyProperty IsShwoIconProperty =
DependencyProperty.Register("IsShwoIcon", typeof(bool), typeof(MessageCard), new PropertyMetadata(default(bool))); public bool IsShwoIcon
{
get { return (bool)GetValue(IsShwoIconProperty); }
set { SetValue(IsShwoIconProperty, value); }
} public static readonly DependencyProperty IsClearableProperty =
DependencyProperty.Register("IsClearable", typeof(bool), typeof(MessageCard), new PropertyMetadata(default(bool), OnIsClearbleChanged)); public bool IsClearable
{
get { return (bool)GetValue(IsClearableProperty); }
set { SetValue(IsClearableProperty, value); }
} private static void OnIsClearbleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is MessageCard messageCard)
{
RoutedEventHandler handle = (sender, args) =>
{
if (VisualTreeHelper.GetParent(messageCard) is Panel panel)
{
// 退出动画
Storyboard exitStoryboard = new Storyboard(); DoubleAnimation exitOpacityAnimation = new DoubleAnimation
{
From = 1,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(exitOpacityAnimation, new PropertyPath(FrameworkElement.OpacityProperty)); DoubleAnimation exitTransformAnimation = new DoubleAnimation
{
From = 0,
To = -30,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(exitTransformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); exitStoryboard.Children.Add(exitOpacityAnimation);
exitStoryboard.Children.Add(exitTransformAnimation); // 动画完成
exitStoryboard.Completed += (a, b) =>
{
panel.Children.Remove(messageCard);
RoutedEventArgs eventArgs = new RoutedEventArgs(MessageCard.CloseEvent, messageCard);
messageCard.RaiseEvent(eventArgs);
}; messageCard.BeginStoryboard(exitStoryboard); // 执行动画
}
};
messageCard.Foreground =new SolidColorBrush( Colors.Black);
messageCard.Loaded += (sender, arg) =>
{
if (messageCard.Template.FindName("clearButton", messageCard) is Button clearButton)
{
if (messageCard.IsClearable)
{
clearButton.Click += handle;
}
else
{
clearButton.Click -= handle;
}
}
}; messageCard.Unloaded += (sender, arg) =>
{
if (messageCard.Template.FindName("clearButton", messageCard) is Button clearButton)
{
if (messageCard.IsClearable)
{
clearButton.Click -= handle;
}
}
};
}
}
#endregion }
}

2:创建名为MessageWindow的窗体

<Window x:Class="Zt.UI.Silver.MessageWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Zt.UI.Silver"
mc:Ignorable="d"
Background="Transparent" WindowStyle="None" AllowsTransparency="True" WindowState="Maximized"
ShowInTaskbar="False" WindowStartupLocation="CenterOwner" VerticalAlignment="Top" Topmost="True"> <StackPanel x:Name="messageStackPanel" Margin="10"> </StackPanel>
</Window>

后台代码:

 public partial class MessageWindow : Window
{
private static MessageWindow messageWindow = null; private MessageWindow()
{
InitializeComponent();
} public static MessageWindow GetInstance()
{
if (messageWindow == null)
{
messageWindow = new MessageWindow();
}
else if (!messageWindow.IsLoaded)
{
messageWindow = new MessageWindow();
}
return messageWindow;
} public void AddMessageCard(MessageCard messageCard, int millisecondTimeOut)
{
messageCard.Close += MessageCard_Close; messageStackPanel.Children.Add(messageCard); // 进入动画
Storyboard enterStoryboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation
{
From = 0,
To = 1,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); DoubleAnimation transformAnimation = new DoubleAnimation
{
From = -30,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(transformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); enterStoryboard.Children.Add(opacityAnimation);
enterStoryboard.Children.Add(transformAnimation); // 退出动画
Storyboard exitStoryboard = new Storyboard(); DoubleAnimation exitOpacityAnimation = new DoubleAnimation
{
From = 1,
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(exitOpacityAnimation, new PropertyPath(OpacityProperty)); DoubleAnimation exitTransformAnimation = new DoubleAnimation
{
From = 0,
To = -30,
Duration = new Duration(TimeSpan.FromMilliseconds(300)),
EasingFunction = new CubicEase { EasingMode = EasingMode.EaseIn }
};
Storyboard.SetTargetProperty(exitTransformAnimation, new PropertyPath("(UIElement.RenderTransform).(TranslateTransform.Y)")); exitStoryboard.Children.Add(exitOpacityAnimation);
exitStoryboard.Children.Add(exitTransformAnimation); // 进入动画完成
if (millisecondTimeOut > 0)
{
enterStoryboard.Completed += async (sender, e) =>
{
await Task.Run(() =>
{
Thread.Sleep(millisecondTimeOut);
}); Dispatcher.Invoke(() =>
{
messageCard.BeginStoryboard(exitStoryboard);
});
};
} // 退出动画完成
exitStoryboard.Completed += (sender, e) =>
{
Dispatcher.Invoke(() =>
{
messageStackPanel.Children.Remove(messageCard);
if (messageStackPanel.Children.Count == 0)
{
this.Close();
}
});
}; messageCard.BeginStoryboard(enterStoryboard);
} /// <summary>
/// 消息卡片关闭按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MessageCard_Close(object sender, RoutedEventArgs e)
{
if (messageStackPanel.Children.Count == 0)
{
this.Close();
}
}
}

三:添加转换器BoolToVisibilityConverter

 public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
{
return Visibility.Visible;
}
else
{
return Visibility.Collapsed;
}
} public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}

  

四:用法

APP引用

 <ResourceDictionary Source="pack://application:,,,/Zt.UI.Silver;component/Themes/MessageCard.xaml" />
<Style TargetType="{x:Type local:MessageCard}" BasedOn="{StaticResource MessageCard}"/>

Main 下使用

<zt:MessageContainer Identifier="MessageContainer" Grid.RowSpan="10"/>

CS:后台代码

局部提示 Message.ShowError("MessageContainer","123",1000);
全局提示 Message.ShowError("123",1000);

五:演示

WPF自定义控件三:消息提示框的更多相关文章

  1. WPF 实现带蒙版的 MessageBox 消息提示框

    WPF 实现带蒙版的 MessageBox 消息提示框 WPF 实现带蒙版的 MessageBox 消息提示框 作者:WPFDevelopersOrg 原文链接: https://github.com ...

  2. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  3. Android应用开发学习之Toast消息提示框

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 本文我们来看Toast消息提示框的用法.使用Toast消息提示框一般有三个步骤: 1.  创建一个Toast对象.可 ...

  4. Android消息提示框Toast

    Android消息提示框Toast Toast是Android中一种简易的消息提示框.和Dialog不一样的是,Toast是没有焦点的,toast提示框不能被用户点击,而且Toast显示的时间有限,t ...

  5. 自定义iOS 中推送消息 提示框

    看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...

  6. Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog)

    Android第三方开源对话消息提示框:SweetAlertDialog(sweet-alert-dialog) Android第三方开源对话消息提示框:SweetAlertDialog(sweet- ...

  7. 精美舒适的对话消息提示框--第三方开源--SweetAlertDialog

    SweetAlertDialog(sweet-alert-dialog)是一个套制作精美.动画效果出色生动的Android对话.消息提示框 SweetAlertDialog(sweet-alert-d ...

  8. Android:Toast简单消息提示框

    Toast是简单的消息提示框,一定时间后自动消失,没有焦点. 1.简单文本提示的方法: Toast.makeText(this, "默认的toast", Toast.LENGTH_ ...

  9. JS~Boxy和JS模版实现一个标准的消息提示框

    面向对象的封装 面向对象一个入最重要的特性就是“封装”,将一些没有必要公开的方法和属性以特定的方式进行组装,使它对外只公开一个接口,外界在调用它时,不需要关注它实现的细节,而只要关注它的方法签名即可, ...

随机推荐

  1. 同步工具——Exchanger

    本博客系列是学习并发编程过程中的记录总结.由于文章比较多,写的时间也比较散,所以我整理了个目录贴(传送门),方便查阅. 并发编程系列博客传送门 本文是转载文章,原文请见这里 一.Exchanger简介 ...

  2. Python协程你学会了吗?

    在学习协程之前,你需要先知道协程是什么?协程又称为微线程,一个程序可以包含多个协程,可以对比与一个进程包含多个线程,因而下面我们来比较协程和线程.我们知道多个线程相对独立,有自己的上下文,切换受系统控 ...

  3. linux学习之路第三天(vim和vi使用)

    vi和vim编辑器 vi和vim的三种常见模式 1.正常模式 在正常模式下,我们可以使用快捷键 以vim打开一个档案就直接进入一般模式了(这是默认的模式).在这个模式中,你可以使用 上下左右按键来移动 ...

  4. Java | 一个".java"源文件中是否可以包括多个类(不包括内部类)

    第一种情况:(有public) 定义一个java源文件(Hello.java),里面只有一个类: public class Hello { public static void main(string ...

  5. C语言:变量

    变量: 1.在程序运行过程中,值可以改变的量称为变量 2.每个变量都有一个名字,称为变量名 3.每个变量都必须进行变量说明,指明变量的类型 4.每个变量都有一个对应的地址,写法:&变量名 5. ...

  6. 详解Lombok中的@Builder用法

    Builder 使用创建者模式又叫建造者模式.简单来说,就是一步步创建一个对象,它对用户屏蔽了里面构建的细节,但却可以精细地控制对象的构造过程. 基础使用 @Builder注释为你的类生成相对略微复杂 ...

  7. nginx+waf防火墙

    1.官网下载nginx源码包(nginx-1.20.0.tar.gz) 新建nginx安装目录​mkdir -p /opt/nginx​新增nginx运行用户​useradd -s /sbin/nol ...

  8. [刘阳Java]_了解BeanFactory_第4讲

    为什么说我们这篇文章只是说了解一下BeanFactory.因为BeanFactory内在的机制与代码实现实在是太强大了,在这一点我确实不敢滥竽充数. 1. 那么我们又如何去了解BeanFactory, ...

  9. vite插件-自动生成vue组件文档

    特点 支持热更新 快速启动,依赖于 vite,无需另起服务 自动生成组件导航 ui 采用了vant-ui的样式 核心方法覆盖率达到了 92.86% 使用 yarn add vite-plugin-vu ...

  10. 【剑指offer】50.数组中重复出现的数字

    50.数组中重复出现的数字 知识点:数组:Set的不可重复性 题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重 ...