微信公眾號:Dotnet9,網站:Dotnet9,問題或建議:請網站留言,
如果對您有所幫助:歡迎贊賞,
.NET CORE(C#) WPF 抽屜式選單
閱讀導航
- 本文背景
- 代碼實作
- 本文參考
- 原始碼
1. 本文背景
使用簡單影片實作抽屜式選單

2. 代碼實作
使用 .NET CORE 3.1 創建名為 “AnimatedColorfulMenu” 的WPF模板專案,添加1個Nuget庫:MaterialDesignThemes,版本為最新預覽版3.1.0-ci948,
解決方案主要檔案目錄組織結構:
- AnimatedColorfulMenu
- App.xaml
- MainWindow.xaml
2.1 引入樣式
檔案【App.xaml】,在 StartupUri 中設定啟動的視圖【MainWindow.xaml】,并在【Application.Resources】節點增加 MaterialDesignThemes庫的樣式檔案:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
2.2 演示表單布局
檔案【MainWindow.xaml】,代碼不多,主要看左側選單,啟動時,選單在顯示表單左側-150位置;點擊展開選單,使用簡單的影片,慢慢呈現在顯示表單左側,原始碼如下:
<Window x:Class="AnimatedColorfulMenu.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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d" Height="600" Width="1080" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen" WindowStyle="None">
<Window.Resources>
<Storyboard x:Key="CloseMenu">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="GridMenu">
<EasingDoubleKeyFrame KeyTime="0" Value=https://www.cnblogs.com/Dotnet9-com/p/"150"/>
3.本文參考
- 視頻一:C# WPF Material Design UI: Animated Colorful Navigation Drawer,配套原始碼:AnimatedColorfulMenu,
- C# WPF開源控制元件庫《MaterialDesignInXAML》
4.原始碼
效果圖實作代碼在文中已經全部給出,可直接Copy,按解決方案目錄組織代碼檔案即可運行,
除非注明,文章均由 Dotnet9 整理發布,歡迎轉載,
轉載請注明本文地址:https://dotnet9.com/7397.html
歡迎掃描下方二維碼關注 Dotnet9 的微信公眾號,本站會及時推送最新技術文章
時間如流水,只能流去不流回!
點擊《【閱讀原文】》,本站還有更多技術類文章等著您哦!!!
此刻順便為我點個《【再看】》可好?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/8185.html
標籤:WPF

