layouts/common/PopupWindow.xaml.cs

(完整代码) 1KB

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace tablegen2.layouts
{
    /// <summary>
    /// PopupWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PopupWindow : Window
    {
        public bool IsEscapeClose { get; set; }
        public event Func<bool> PreClosingEvent;
        public UserControl Panel { get; internal set; }

        public PopupWindow(UserControl uc)
        {
            InitializeComponent();
            gridContainer.Children.Add(uc);
            IsEscapeClose = true;
            Panel = uc;
            
            this.MaxWidth = SystemParameters.WorkArea.Width;
            this.MaxHeight = SystemParameters.WorkArea.Height;
            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.SystemIdle,
               new Action(() =>
               {
                   this.SizeToContent = SizeToContent.Manual;
                   this.MaxWidth = System.Double.PositiveInfinity;
                   this.MaxHeight = System.Double.PositiveInfinity;
               }));
        }

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (IsEscapeClose && e.Key == Key.Escape)
            {
                e.Handled = true;
                this.Close();
            }
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            if (PreClosingEvent != null && !PreClosingEvent.Invoke())
                e.Cancel = true;
            else
                base.OnClosing(e);
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。