
1、安装nuget包:H.Modules.Messages.Dialog

2、执行代码
- private async void Button_AdornerDialog_Click(object sender, RoutedEventArgs e)
- {
- await AdornerDialog.ShowPresenter("我是AdornerDialog");
- }
AdornerDialog会使用MainWindow的Adorner层去显示遮罩层的对话框,不需要额外配置可以直接使用
更多其他可选设置
- var r = await AdornerDialog.ShowPresenter("我是AdornerDialog", x =>
- {
- x.DialogButton = DialogButton.SumitAndCancel;
- x.Height = 100;
- x.VerticalContentAlignment = VerticalAlignment.Top;
- x.Padding = new Thickness(20);
- });
- if (r == true)
- System.Diagnostics.Debug.WriteLine("点击了确定");
- if (r == null)
- System.Diagnostics.Debug.WriteLine("点击了关闭按钮");
- if (r == true)
- System.Diagnostics.Debug.WriteLine("点击了取消");
效果如下

源码位置
Adorner 类 (System.Windows.Documents) | Microsoft Learn
GitHub - HeBianGu/WPF-ControlDemo: 示例
GitHub - HeBianGu/WPF-ControlBase: Wpf封装的自定义控件资源库
GitHub - HeBianGu/WPF-Control: WPF轻量控件和皮肤库
System.Windows.Controls 命名空间 | Microsoft Learn
HeBianGu的个人空间-HeBianGu个人主页-哔哩哔哩视频