快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

C#中怎么利用WPF实现一个抽屉效果

这篇文章给大家介绍C#中怎么利用 WPF实现一个抽屉效果,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、重庆小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了洪江管理区免费建站欢迎大家使用!

代码实现

站长使用.Net Core 3.1创建的WPF工程,创建PopUpAndNav解决方案后,需要添加两个Nuget库:MaterialDesignThemes和MaterialDesignColors。

C#中怎么利用 WPF实现一个抽屉效果添加Material两个库

工程比较简单,主要就是演示窗口MainWindow:

C#中怎么利用 WPF实现一个抽屉效果

解决方案结构

代码不多,我就全部贴上代码吧。

添加MaterialDesignInXaml样式:App.xaml

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:PopUpAndNav"
            StartupUri="MainWindow.xaml">
   
       
           
               
               
               
               
           

       

   


演示窗口MainWindow.xaml代码,使用简单的自定义窗口,看效果图,有右上角的标题栏菜单及左上角的抽屉菜单:

       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:PopUpAndNav"
       xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
       mc:Ignorable="d" Foreground="White"
       Title="MainWindow" Height="600" Width="1080" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowStyle="None">
   
       
           
               
               
           

       

       
           
               
               
           

       

   


   
       
           
       

       
           
       

   

   
   
       
           
           
               
               
                   
                       
                   
               

               
                   
                       
                           
                           
                       

                   

                   
                       
                           
                           
                       

                   

                   
                       
                           
                           
                       

                   

                   
                       
                           
                           
                       

                   

                   
                       
                           
                           
                       

                   

               

           
       

   

后台MainWindow.xaml.cs,主要是处理窗体关闭事件及抽屉菜单的展开与折叠:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PopUpAndNav
{
   ///
   /// Interaction logic for MainWindow.xaml
   ///

   public partial class MainWindow : Window
   {
       public MainWindow()
       {
           InitializeComponent();
       }

       private void ButtonPopUpLogout_Click(object sender, RoutedEventArgs e)
       {
           Application.Current.Shutdown();
       }

       private void ButtonOpenMenu_Click(object sender, RoutedEventArgs e)
       {
           ButtonOpenMenu.Visibility = Visibility.Collapsed;
           ButtonCloseMenu.Visibility = Visibility.Visible;
       }

       private void ButtonCloseMenu_Click(object sender, RoutedEventArgs e)
       {
           ButtonOpenMenu.Visibility = Visibility.Visible;
           ButtonCloseMenu.Visibility = Visibility.Collapsed;
       }
       
       private void GridTitle_MouseDown(object sender, MouseButtonEventArgs e)
       {
           DragMove();
       }
   }
}

关于C#中怎么利用 WPF实现一个抽屉效果就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章名称:C#中怎么利用WPF实现一个抽屉效果
当前地址:http://6mz.cn/article/igcsgj.html

其他资讯