pan class="w"> {varstartTime=Process.GetCurrentProcess().StartTime;if(_loaded)return;_loaded=true;varhandle=newWindowInteropHelper(System.Windows.Application.Current.MainWindow).Handle;System.Windows.Application.Current.MainWindow.LocationChanged+=MainWindow_LocationChanged;Visibilityv=Visibility;varxaml=FrameworkElementSerializer.Serialize(ContentasFrameworkElement);objectdc=this.DataContext;Content=null;varmain_dispatcher=System.Windows.Application.Current.Dispatcher;System.Windows.Application.Current.MainWindow.RegisterForLoadedOrNow((_,__)=>{Threadthread=newThread(()=>{main_dispatcher.ShutdownFinished+=(x,y)=>{if(_window!=null){_window.Invoke(()=>{_window.Close();});}};_window=newWindow();_window.WindowStyle=WindowStyle.None;_window.ResizeMode=ResizeMode.NoResize;_window.ShowInTaskbar=false;_window.AllowsTransparency=true;_window.Background=Brushes.Transparent;_window.WindowStartupLocation=WindowStartupLocation.Manual;SyncBounds();if(v!=Visibility.Visible){_window.Opacity=0;}newWindowInteropHelper(_window).Owner=handle;_window.ShowActivated=false;varcloned=FrameworkElementSerializer.Deserialize(xaml);cloned.DataContext=dc;_window.Content=cloned;_window.Show();SyncBounds();System.Windows.Threading.Dispatcher.Run();});thread.SetApartmentState(ApartmentState.STA);thread.IsBackground=true;thread.Start();});}}/// <summary>/// Handles the LocationChanged event of the MainWindow control./// </summary>/// <param name="sender">The source of the event.</param>/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>privatevoidMainWindow_LocationChanged(objectsender,EventArgse){SyncBounds();}/// <summary>/// Synchronizes the bounds of the window with the bounds of the original control./// </summary>publicvoidSyncBounds(){if(_window!=null){this.BeginInvoke(()=>{Pointlocation=PointToScreen(newPoint(0,0));Sizesize=newSize(ActualWidth,ActualHeight);_window.BeginInvoke(()=>{_window.Top=location.Y;_window.Left=location.X;_window.Width=size.Width;_window.Height=size.Height;});});}}/// <summary>/// Hides the element window./// </summary>privatevoidHideWindow(){if(_window!=null){_window.BeginInvoke(()=>{_window.Hide();});}}/// <summary>/// Shows the element window./// </summary>privatevoidShowWindow(){if(_window!=null){_window.BeginInvoke(()=>{_window.Opacity=1;_window.Show();});}}}}