czw
2025-07-03 69dbf7b5848a7e657b2911a9662e6dbd4f8f516b
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/½çÃæ/View1.xaml.cs
@@ -39,18 +39,51 @@
        public View1()
        {
            InitializeComponent();
         #region é™åˆ¶è¿è¡Œå®žä¾‹æ•°é‡
            #region é™åˆ¶è¿è¡Œå®žä¾‹æ•°é‡
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("AuxAllWCS");
            if (processes.Length > System.Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["InstanceLimit"]))
            {
                System.Windows.MessageBox.Show("运行失败:运行实例数量已超出限制");
                this.Close();
            }
         #endregion
            this.DataContext = ViewModel.CreateInstance(this,typeof(View1));
            #endregion
            this.DataContext = ViewModel.CreateInstance(this, typeof(View1));
            this.Loaded += (this.DataContext as ViewModel).View1_LoadEvent;
         this.Closing += (this.DataContext as ViewModel).View1_CloseEvent;
            this.Closing += (this.DataContext as ViewModel).View1_CloseEvent;
            commmd();
        }
        public async void commmd()
        {
            await webView.EnsureCoreWebView2Async();
        labbb:
            if (!string.IsNullOrEmpty(HttpServer._listenerPrefix))
                if (webView.Source != new Uri(HttpServer._listenerPrefix))
                {
                    webView.CoreWebView2.Navigate(HttpServer._listenerPrefix + "/index.html");
                    goto EndInit;
                }
            System.Threading.Thread.Sleep(2000);
            goto labbb;
        EndInit:
            Console.WriteLine("end Set Uri");
            webView.PreviewKeyDown += (object sender, KeyEventArgs e) =>
            {
                // æ£€æŸ¥æŒ‰ä¸‹çš„键是否是 F12,如果是,禁止其默认行为
                if (e.Key == Key.F12)
                {
                    e.Handled = true;
                }
            };
            await webView.CoreWebView2.ExecuteScriptAsync(
                @"
                    document.addEventListener('contextmenu', function(event) {
                        event.preventDefault();
                    }, false);
                "
            );
        }
    }
}