WPF基础之界面设计(MaterialDesignThemes)

界面设计源码地址:https://download.csdn.net/download/yigu4011/88011184

 WPF基础之界面设计(MaterialDesignThemes)_第1张图片

1、Nuget安装MaterialDesignThemes框架,安装LiveCharts、LiveCharts.Wpf(用来添加曲线,也可以下载LiveCharts.dll、LiveCharts.Wpf.dll,然后引用DLL)

WPF基础之界面设计(MaterialDesignThemes)_第2张图片

 2、打开阿里巴巴素材库,下载素材,解压素材,将素材文件iconfont.ttf添加到项目

WPF基础之界面设计(MaterialDesignThemes)_第3张图片WPF基础之界面设计(MaterialDesignThemes)_第4张图片

3、App.xaml中添加资源代码:


    
        
            
                
                
                
                
            
        
    

 4、在MainWindow.xaml添加MaterialDesignThemes、LiveCharts、LiveCharts.Wpf的引用

    xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"

5、左边菜单栏关键性代码如下:(全部源码可去上方CSDN代码地址自由下载)

            
                

                

                

                

                

                
            

 6、右边显示关键代码如下:

            
                
                    
                        
                            
                            
                        

                        
                            
                                
                            
                            
                                
                                
                                
                            
                            
                                
                                
                                
                            
                            
                            
                            
                                
                                    
                                
                            
                        

                        
                            
                                
                                
                            
                            
                                
                                
                            
                            
                                
                                
                                
                            
                            
                        
                    
                
                
                    
                        
                            
                            
                        
                        
                            
                                
                            
                            
                                
                                
                                
                            
                            
                                
                                
                                
                            
                            
                            

                            
                                
                                    
                                
                            
                        

                        
                            
                                
                                
                            
                            
                                
                                
                                
                            
                            
                        
                    
                
                
                    
                        
                            
                            
                        
                        
                            
                                
                            
                            
                                
                                
                                
                            
                            
                                
                                
                                
                            
                            
                            
                            
                                
                                    
                                
                                
                                    
                                
                            

                        

                        
                            
                                
                                
                            
                            
                                
                                
                                
                            
                            
                        
                    
                
            

6、关键事件代码如下:

/// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        Point _pressedPosition;
        bool _isDragMoved = false;
        private void Window_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _pressedPosition = e.GetPosition(this);
        }
        private void Window_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (Mouse.LeftButton == MouseButtonState.Pressed && _pressedPosition != e.GetPosition(this))
            {
                _isDragMoved = true;
                DragMove();
            }
        }
        private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_isDragMoved)
            {
                _isDragMoved = false;
                e.Handled = true;
            }
        }


        private void btnMin_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void btnMax_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

    }

你可能感兴趣的:(WPF基础,wpf)