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

关于C#在WPF中如何使用“抽屉”控件

关于C#在WPF中如何使用“抽屉”控件

  • 1.前提准备
  • 2.XAML代码
  • 3.对应的C#代码
  • 4.显示效果

1.前提准备

需要引用MaterialDesign控件库,关于如何引用,请参照文章——关于C#如何引用MaterialDesign控件库

2.XAML代码

<Window x:Class="MaterialDesign_Test.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:MaterialDesign_Test"xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML"xmlns:system="clr-namespace:System;assembly=mscorlib"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><Button Content="{materialDesign:PackIcon Kind=ArrowRight}" Width="30" Height="30" Margin="94,207,668,182" Click="Button_Click" /><materialDesign:DrawerHost x:Name="drawerHost"><!-- 抽屉内容 --><materialDesign:DrawerHost.RightDrawerContent><Grid Background="LightGray" Width="160"><TextBlock Text="这是抽屉内容" VerticalAlignment="Center" HorizontalAlignment="Center"/></Grid></materialDesign:DrawerHost.RightDrawerContent></materialDesign:DrawerHost></Grid>
</Window>

3.对应的C#代码

using System.Windows;namespace MaterialDesign_Test
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){//drawerHost.IsLeftDrawerOpen = true;drawerHost.IsRightDrawerOpen = true;}}
}

4.显示效果

点击蓝色按钮,出现如图所示的效果。
在这里插入图片描述

http://www.lryc.cn/news/394666.html

相关文章:

  • 运维Tips | Ubuntu 24.04 安装配置 xrdp 远程桌面服务
  • ExcelVBA运用Excel的【条件格式】(二)
  • 肠道和大脑中犬尿氨酸代谢途径的紊乱
  • vue通过后台返回的数字显示不同的文字内容,多个内容用、隔开
  • Flume工具详解
  • vulhub-activemq(CVE-2016-3088)
  • 上海市计算机学会竞赛平台2024年6月月赛丙组超级奇数
  • 速盾:cdn业务优化
  • 重生奇迹mu的地图名
  • 【CSS】缩写属性gap
  • Perl 语言开发(八):子程序和模块
  • 自注意力机制和多头注意力机制区别
  • 数据结构第14节 加权图
  • 128陷阱(超详细)
  • STM32自己从零开始实操08:STM32主控原理图
  • Ubuntu20.04配置TurtleBot3 Waffle Pi远程控制
  • SaaS产品和独立部署型产品有什么区别,该怎么选择?
  • 【Linux】压缩命令——gzip,bzip2,xz
  • 【Java13】包
  • 从零到一:Python自动化测试的详细指南!
  • iOS中多个tableView 嵌套滚动特性探索
  • TCP/IP模型和OSI模型的区别
  • (九)绘制彩色三角形
  • 短信群发平台适用于哪些行业?
  • 1. 倍数
  • C#常用关键字举例
  • stm32——外部中断EXTI
  • Solidity:变量数据存储和作用域 storage/memory/calldata
  • ElementUI中的el-table解决宽度问题 - 根据内容自动撑开
  • react apollo hooks