WPF自定义DatePicker日期样式,并且加“今天”按钮

WPF自定义DatePicker日期样式,并且加“今天”按钮_第1张图片

 1.界面

 

2.资源字典DatePickerStyle



    
    #FFE8EDF9
    #FFC5CBF9
    #1B3569

    #FFE8EDF9
    #FFC5CBF9
    #FF888888

    #1890FF
    #FFDDDDDD

    
    #104B7E
    
    #104B7E
    #056293

    #1890FF
    #056293


    
    White
    #1890FF

    
    #FFC5CBF9
    #FF888888
    #056293

    #FF888888
    #FF444444

    #FFAAAAAA
    #056293

    #056293

    
    #FFC5CBF9
    white
    #FFC5CBF9

    #1B3569

    
        
        
        
    

    
        
            
                
                
                
                
            
        
    

    
    

    
    

    
    
        
            
                
                    
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                
            
            
            
                
                    
                        
                    
                
            
        
    

    
    
        
            
                
                    
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                
            
            
            
                
                    
                        
                    
                
            
        
    

    
    
        
            
                
                    
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                
            
            
        
    

    
                                                
                                            
                                        
                                    
                                
                            
                        
                        
                    
                    
                        
                            
                        
                        
                            
                            
                        
                        
                            
                            
                        
                    
                
            
        
    

    
    
    

    
    
   
   

3.事件类DatePickerCommand-今天按钮

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Tend.UAC.Commands
{
    public partial class DatePickerCommand : ResourceDictionary
    {
        public DatePickerCommand()
        {
            InitializeComponent();

        }
        public void TodayBtncommand(object sender, MouseButtonEventArgs e)
        {
            var Media = ((System.Windows.Media.Visual)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)((FrameworkElement)sender).Parent).Parent).Parent).Parent).Parent).Parent);
            ((System.Windows.Controls.Calendar)((FrameworkElement)((FrameworkElement)Media).TemplatedParent).TemplatedParent).SelectedDate = DateTime.Now;
            ((System.Windows.Controls.Primitives.Popup)((FrameworkElement)((FrameworkElement)((FrameworkElement)Media).TemplatedParent).TemplatedParent).Parent).IsOpen = false;
        }
    }
}

你可能感兴趣的:(.NET,WPF,wpf,DatePicker)