120 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Runtime.CompilerServices;
 | 
						|
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 Future.Contract
 | 
						|
{
 | 
						|
    [TemplatePart(Name = "CloseHandle", Type = typeof(Button))]         //关闭按钮
 | 
						|
    //[TemplatePart(Name = "OpacityArea", Type = typeof(UIElement))]      //透视区域
 | 
						|
    public class DrawerTemplate : ContentControl
 | 
						|
    {
 | 
						|
        private Button? _CloseHandle;
 | 
						|
        //private UIElement? _OpacityArea;
 | 
						|
        static DrawerTemplate()
 | 
						|
        {
 | 
						|
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DrawerTemplate), new FrameworkPropertyMetadata(typeof(DrawerTemplate)));
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 请求关闭事件
 | 
						|
        /// </summary>
 | 
						|
        public event Action? ApplyCloseDrawer;
 | 
						|
 | 
						|
        public override void OnApplyTemplate()
 | 
						|
        {
 | 
						|
            base.OnApplyTemplate();
 | 
						|
            this._CloseHandle = this.Template.FindName("CloseHandle", this) as Button;
 | 
						|
            //this._OpacityArea = this.Template.FindName("OpacityArea", this) as UIElement;
 | 
						|
            if (this._CloseHandle != null) this._CloseHandle.Click += (s, e) => this.ApplyCloseDrawer?.Invoke();
 | 
						|
        }
 | 
						|
 | 
						|
        public DrawerTemplate Clone() 
 | 
						|
        {
 | 
						|
            return new DrawerTemplate() 
 | 
						|
            {
 | 
						|
                Background = this.Background,
 | 
						|
                Foreground = this.Foreground,
 | 
						|
                BorderBrush = this.BorderBrush,
 | 
						|
                BorderThickness = this.BorderThickness,
 | 
						|
                HorizontalAlignment = this.HorizontalAlignment,
 | 
						|
                VerticalAlignment = this.VerticalAlignment,
 | 
						|
                HorizontalContentAlignment = this.HorizontalContentAlignment,
 | 
						|
                VerticalContentAlignment = this.VerticalContentAlignment,
 | 
						|
                Dock = this.Dock,
 | 
						|
                FontFamily = this.FontFamily,
 | 
						|
                FontSize = this.FontSize,
 | 
						|
                FontStretch=this.FontStretch,
 | 
						|
                FontStyle = this.FontStyle,
 | 
						|
                FontWeight = this.FontWeight,
 | 
						|
                //Template = this.Template,
 | 
						|
                Style = this.Style
 | 
						|
            };
 | 
						|
        }
 | 
						|
 | 
						|
        #region   依赖属性
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 抽屉标题
 | 
						|
        /// </summary>
 | 
						|
        public string Title
 | 
						|
        {
 | 
						|
            get { return (string)GetValue(TitleProperty); }
 | 
						|
            set { SetValue(TitleProperty, value); }
 | 
						|
        }
 | 
						|
 | 
						|
        // Using a DependencyProperty as the backing store for Title.  This enables animation, styling, binding, etc...
 | 
						|
        public static readonly DependencyProperty TitleProperty =
 | 
						|
            DependencyProperty.Register("Title", typeof(string), typeof(DrawerTemplate), new PropertyMetadata(""));
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 停靠方向
 | 
						|
        /// </summary>
 | 
						|
        public Dock Dock
 | 
						|
        {
 | 
						|
            get { return (Dock)GetValue(DockProperty); }
 | 
						|
            set { SetValue(DockProperty, value); }
 | 
						|
        }
 | 
						|
 | 
						|
        // Using a DependencyProperty as the backing store for Dock.  This enables animation, styling, binding, etc...
 | 
						|
        public static readonly DependencyProperty DockProperty =
 | 
						|
            DependencyProperty.Register("Dock", typeof(Dock), typeof(DrawerTemplate), new PropertyMetadata(Dock.Right));
 | 
						|
 | 
						|
        public Visibility HandleVisibility
 | 
						|
        {
 | 
						|
            get { return (Visibility)GetValue(HandleVisibilityProperty); }
 | 
						|
            set { SetValue(HandleVisibilityProperty, value); }
 | 
						|
        }
 | 
						|
 | 
						|
        // Using a DependencyProperty as the backing store for HandleVisibility.  This enables animation, styling, binding, etc...
 | 
						|
        public static readonly DependencyProperty HandleVisibilityProperty =
 | 
						|
            DependencyProperty.Register("HandleVisibility", typeof(Visibility), typeof(DrawerTemplate), new PropertyMetadata(Visibility.Visible));
 | 
						|
 | 
						|
 | 
						|
 | 
						|
        public double TitleHeight
 | 
						|
        {
 | 
						|
            get { return (double)GetValue(TitleHeightProperty); }
 | 
						|
            set { SetValue(TitleHeightProperty, value); }
 | 
						|
        }
 | 
						|
 | 
						|
        // Using a DependencyProperty as the backing store for TitleHeight.  This enables animation, styling, binding, etc...
 | 
						|
        public static readonly DependencyProperty TitleHeightProperty =
 | 
						|
            DependencyProperty.Register("TitleHeight", typeof(double), typeof(DrawerTemplate), new PropertyMetadata(60.0));
 | 
						|
 | 
						|
 | 
						|
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
}
 |