Guest User

Untitled

a guest
Jul 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. private void WpfUsercontrol_OnLoaded(object sender, RoutedEventArgs e)
  2. {
  3. Window window = Window.GetWindow(this);
  4. if (window != null)
  5. window.Closing += window_closing;
  6.  
  7. Form form = this.Parent as Form;
  8. //Error: Cannot convert from System.Windows.DependencyObject to System.Windows.Forms.Form
  9. }
  10.  
  11. var hwndSource = (HwndSource)PresentationSource.FromDependencyObject(this);
  12. var host = (ElementHost)Control.FromChildHandle(hwndSource.Handle);
  13. Form form = (Form)host.TopLevelControl;
Add Comment
Please, Sign In to add comment