-
Apr 28th, 2019, 06:44 AM
#1
Thread Starter
Member
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?
-
May 16th, 2019, 01:01 AM
#2
Thread Starter
Member
Re: Embed an application into a WPF
I was able to get a lot further over here.
Moving to CefSharp anyway .....
-
Mar 16th, 2020, 11:51 PM
#3
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|