Results 1 to 3 of 3

Thread: Embed an application into a WPF

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2016
    Posts
    35

    Embed an application into a WPF

    Hi there,

    I'm in the process of porting my project to WPF.
    I'm trying to launch an application (SmatraPDF) in a SlackPanel within my WPF program that has got several controls.

    Code:
    {
    	/// <summary>
    	/// Interaction logic for Window1.xaml
    	/// </summary>
    	public partial class Window1 : Window
    	{
    		public Window1()
    		{
    		InitializeComponent();
    			
    		this.PreviewKeyDown += new KeyEventHandler(HandleEsc);
    		}
    		
    	        private void HandleEsc(object sender, KeyEventArgs e)
    {
                          if (e.Key == Key.Escape)
                          Close();
                         if (e.Key == Key.F1)
        	             WindowState = WindowState.Minimized;
    }
    	
    	           [DllImport("user32.dll")]
                       static extern IntPtr SetParent(IntPtr hwc, IntPtr hwp);
    	
    		  void button1_Click(object sender, RoutedEventArgs e)
    		{
    		
    		 Process p = Process.Start("Path_to_SumatraPDF.exe");
    		 p.WaitForInputIdle();
    		 SetParent(p.MainWindowHandle, StackPanel.Handle);
    
    		}	
    		
    	}
    }
    ... but to no avail as I'm getting the following error:

    Code:
    'System.Windows.Controls.StackPanel' does not contain a definition for 'Handle' and no extension method 'Handle' accepting a first argument of type 'System.Windows.Controls.StackPanel' could be found (are you missing a using directive or an assembly reference?) (CS1061) 
    Could anyone please give me a hint?

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2016
    Posts
    35

    Re: Embed an application into a WPF

    I was able to get a lot further over here.
    Moving to CefSharp anyway .....

  3. #3
    Lively Member
    Join Date
    Jan 2020
    Posts
    120

    Re: Embed an application into a WPF

    Hello, @kmlj

    Follow these steps ,To embed an application into a WPF

    Step 1 : Open the Visual Studio and create a new WPF application.
    Step 2 : Right Click the WpfApplication1 Solution. Then click Add menu and point the User Control...
    Step 3 : Open the Toolbox panel, then click the Choose Items... in the context menu.
    Step 4 : In the pop up Choose Toolbox Items dialog, select the Edraw Office Viewer Component then click the Ok.
    Step 5 : Now the Edraw Office Viewer Component was added in the General tab in the Toolbox. Drag it in the UserControl form.
    Step 6 : Add the following c# code to associate the office component.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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 WpfApplication1
    {
    public partial class Window1 : Window
    {
    public Window1()
    {
    InitializeComponent();
    }
    private void Open_Click(object sender, RoutedEventArgs e)
    {
    _host.Open();
    }
    private void Protect_Click(object sender, RoutedEventArgs e)
    {
    _host.Protect();
    }
    private void Print_Click(object sender, RoutedEventArgs e)
    {
    _host.Print();
    }
    private void Close_Click(object sender, RoutedEventArgs e)
    {
    _host.Close();
    }
    }
    }
    Step 7 : Open the Configuration Manager. Change the Active solution platform as x86 option. Then build and run.

    I hope above information will be useful for you.

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width