当前位置: 首页 > ds >正文

3.1.3 materialDesign:DialogHost 使用介绍

        MaterialDesign是一个为WPF应用程序提供现代化UI组件的库,其中的DialogHost组件用于显示和管理对话框。DialogHost允许你轻松地弹出各种对话框,如消息框、确认框、输入对话框等,并且可以自定义对话框的样式和行为.

        1.IsOpen属性来控制对话框的显示和隐藏。

        2. Identifier属性,用来标记DialogHost.

        3.DialogContent 用于显示对话框的内容;当然也可以单独写一个usercontrol。

一、简单使用

        点击按钮时,直接

<Window x:Class="AhuiPLC_CurveRecord.Window1"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:AhuiPLC_CurveRecord"mc:Ignorable="d"xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"       Title="Window1" Height="450" Width="800"><Grid><StackPanel Orientation="Vertical"><Button Content="Open Dialog" Click="OpenDialog_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/><Button Content="close Dialog" Click="CloseDialog_Click" HorizontalAlignment="Center" VerticalAlignment="Center"Margin="0 10 0 0"/><materialDesign:DialogHost x:Name="MyDialogHost" Identifier="MyDialog" Height="40" Margin="0,100,0,0" ><Border ><TextBlock HorizontalAlignment="Center" Background="LightBlue">"这是diaglog Host中的一个区域"</TextBlock></Border><materialDesign:DialogHost.DialogContent><TextBlock Text="This is a dialog content." HorizontalAlignment="Center" VerticalAlignment="Center"/></materialDesign:DialogHost.DialogContent></materialDesign:DialogHost></StackPanel>  </Grid>
</Window>
 private void OpenDialog_Click(object sender, RoutedEventArgs e){MyDialogHost.IsOpen = true;}// 关闭对话框的方法private void CloseDialog_Click(object sender, RoutedEventArgs e){MyDialogHost.IsOpen = false;}public Window1(){InitializeComponent();this.DataContext = this;}

例2:使用UserControl作为对话框的内容

        主要是直接把UserControls的对话框添加到: dialogContent的内部

 <materialDesign:DialogHost.DialogContent>
     <controls:MyDialogControl/>
 </materialDesign:DialogHost.DialogContent>

对话框如下:

<UserControl x:Class="AhuiPLC_CurveRecord.Controls.MyDialogControl"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:AhuiPLC_CurveRecord.Controls"mc:Ignorable="d" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"   xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf">    <StackPanel Margin="16" Width="300"><TextBlock Text="请输入信息:" Style="{StaticResource MaterialDesignSubtitle1TextBlock}"/><TextBox materialDesign:HintAssist.Hint="用户名" Margin="0,8,0,0"/><PasswordBox materialDesign:HintAssist.Hint="密码" Margin="0,8,0,16"/><StackPanel Orientation="Horizontal" HorizontalAlignment="Right"><Button Content="取消" Command="{x:Static wpf:DialogHost.CloseDialogCommand}"           CommandParameter="False"Margin="0,0,8,0"/><Button Content="确定" Command="{x:Static wpf:DialogHost.CloseDialogCommand}"CommandParameter="True"/></StackPanel></StackPanel>
</UserControl>
<Window x:Class="AhuiPLC_CurveRecord.Window1"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:AhuiPLC_CurveRecord"mc:Ignorable="d"xmlns:controls="clr-namespace:AhuiPLC_CurveRecord.Controls"xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"       Title="Window1" Height="450" Width="800"><Grid><StackPanel Orientation="Vertical"><Button Content="Open Dialog" Click="OpenDialog_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/><Button Content="close Dialog" Click="CloseDialog_Click" HorizontalAlignment="Center" VerticalAlignment="Center"Margin="0 10 0 0"/><materialDesign:DialogHost x:Name="MyDialogHost" Identifier="MyDialog" Height="40" Margin="0,100,0,0" ><Border ><TextBlock HorizontalAlignment="Center" Background="LightBlue">"这是diaglog Host中的一个区域"</TextBlock></Border><materialDesign:DialogHost.DialogContent><controls:MyDialogControl/></materialDesign:DialogHost.DialogContent></materialDesign:DialogHost></StackPanel>  </Grid>
</Window>
private void OpenDialog_Click(object sender, RoutedEventArgs e)
{MyDialogHost.IsOpen = true;
}
// 关闭对话框的方法
private void CloseDialog_Click(object sender, RoutedEventArgs e)
{MyDialogHost.IsOpen = false;
}

http://www.xdnf.cn/news/1621.html

相关文章:

  • Whisper微调及制作方言数据集
  • Golang 闭包学习
  • arm64适配系列文章-第三章-arm64环境上mariadb的部署
  • 一行命令打开iOS模拟器
  • uniapp -- 实现微信小程序、app、H5端视频上传
  • ORACLE RAC环境使用ASM机制零宕机时间更换存储的实践
  • matlab 绘图
  • 【leetcode100】目标和
  • MongoDB副本集搭建与核心机制
  • 【MySQL】基本查询
  • 如何解析商品详情页面
  • 简单几步,开启 Intel VT-x 让电脑“解开CPU封印”
  • SiamMask中的分类分支、回归分支与Mask分支,有何本质差异?
  • 【LLM+Code】Github Copilot Agent/VsCode Agent 模式PromptTools详细解读
  • 【含文档+PPT+源码】基于SpringBoot+vue的疫苗接种系统的设计与实现
  • MySQL总结
  • 深度剖析操作系统核心(第一节):从X86/ARM/MIPS处理器架构到虚拟内存、分段分页、Linux内存管理,再揭秘进程线程限制与优化秘籍,助你成为OS高手!
  • 如何彻底卸载Android Studio?
  • aarcpy 列表函数的使用(1)
  • 分页查询优惠券
  • Unity 使用 ADB 实时查看手机运行性能
  • 【技术派后端篇】技术派中 Session/Cookie 与 JWT 身份验证技术的应用及实现解析
  • 详解springcloudalibaba采用prometheus+grafana实现服务监控
  • Qt UDP组播实现与调试指南
  • leetcode28. 找出字符串中第一个匹配项的下标_简单KMP
  • vue3 实现将html内容导出为图片、pdf和word
  • Linux Awk 深度解析:10个生产级自动化与云原生场景
  • 私钥连接服务器(已经有服务器私钥
  • 安卓adb shell串口基础指令
  • 【激光雷达3D(7)】CenterPoint两阶段细化仅使用BEV特征;PV-RCNN两阶段细化使用体素特征;M3DETRTransformer统一多表征特征