Skip to content

Commit 6b4cd1f

Browse files
authored
Merge pull request #1218 from syncfusion-content/pdfviewer-dev
Revamped the WPF PdfViewer hosting details page
2 parents 31b7326 + 92e27fc commit 6b4cd1f

1 file changed

Lines changed: 24 additions & 42 deletions

File tree

WindowsForms/PDF-Viewer/How-To/How-to-make-Winforms-PdfViewer-have-enriched-features-like-WPF-PdfViewer.md

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,52 @@ documentation: ug
1111
To leverage the advanced features offered by the WPF PdfViewer, such as adding annotations, form filling, signatures, stamps, sticky notes, and more, you can [integrate the WPF PdfViewer into the Windows Forms]( https://support.syncfusion.com/kb/article/7882/how-to-host-pdf-viewer-in-windows-forms-application ) and take advantage of its extensive feature sets.
1212

1313
we can host a WPF PdfViewer control within a Windows Forms application using an ElementHost. By embedding the WPF PdfViewer, you can access advanced features available in the WPF control while maintaining a Windows Forms interface.
14-
To host the WPF PdfViewer in the winforms application follow the below steps,
1514

16-
1. Create an UserControl and add the below XAML code to it.
15+
## Steps to host the WPF PdfViewer in the winforms application
1716

18-
* Add the following Syncfusion® namespace in XAML to make use of the WPF [PdfViewerControl](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html)
17+
1. Add an WPF UserControl and install the [Syncfusion.PdfViewer.WPF](https://www.nuget.org/packages/Syncfusion.PdfViewer.WPF) NuGet package to your WinForms application.
18+
19+
2. Add the following Syncfusion® namespace in XAML to make use of the WPF [PdfViewerControl.](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html)
1920

2021
~~~xaml
2122
<UserControl
2223
xmlns:PdfViewerUserControl="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF">
2324
</UserControl>
2425
~~~
25-
* Declare the WPF [PdfViewerControl](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html) in the XAML page.
26-
27-
~~~xaml
28-
<UserControl x:Class="SampleWF.PdfViewer"
29-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
30-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
31-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
32-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
33-
xmlns:local="clr-namespace:SampleWF"
34-
xmlns:Syncfusion="http://schemas.syncfusion.com/wpf"
35-
mc:Ignorable="d"
36-
xmlns:PdfView="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
37-
Loaded="UserControl_Loaded"
38-
>
3926

27+
3. Add the below code in the XAML page to initialize the WPF PdfViewer.
28+
29+
~~~xaml
4030
<Grid>
4131
<PdfView:PdfViewerControl x:Name="pdfViewer"/>
4232
</Grid>
43-
</UserControl>
44-
~~~
45-
* Add the below line of codes in the code behind file.
33+
~~~
34+
35+
4. Load the PDF file into the PdfViewer when the UserControl is loaded in the application
4636

4737
{% tabs %}
4838
{% highlight c# %}
4939

50-
using System.Windows;
51-
using System.Windows.Controls;
52-
53-
namespace SampleWF
54-
{
55-
/// <summary>
56-
/// Interaction logic for PdfViewer.xaml
57-
/// </summary>
58-
public partial class PdfViewerUserControl : UserControl
40+
/// <summary>
41+
/// Interaction logic for PdfViewer.xaml
42+
/// </summary>
43+
public partial class PdfViewerUserControl : UserControl
44+
{
45+
public PdfViewer()
5946
{
60-
public PdfViewer()
61-
{
62-
InitializeComponent();
63-
}
47+
InitializeComponent();
48+
}
6449

65-
private void UserControl_Loaded(object sender, RoutedEventArgs e)
66-
{
67-
pdfViewer.Load(@"../../Data/Windows Store Apps Succinctly.pdf");
68-
}
50+
private void UserControl_Loaded(object sender, RoutedEventArgs e)
51+
{
52+
pdfViewer.Load(@"../../Data/Windows Store Apps Succinctly.pdf");
6953
}
70-
}
54+
}
7155

7256
{%endhighlight%}
7357
{% endtabs %}
7458

75-
2. Create an ElementHost object in the Form and add the created UserControl's object as child to the ElementHost object.
76-
77-
To do the above step follow the below procedures
59+
5. Add a panel to the form. Create an ElementHost object in the Form and add the created UserControl's object as child to the ElementHost object. Add the elementHost as a child to the panel as mentioned below.
7860

7961
{% tabs %}
8062
{% highlight c# %}
@@ -122,4 +104,4 @@ namespace SampleWF
122104
{%endhighlight%}
123105
{% endtabs %}
124106

125-
You can find the sample for you reference [here](https://www.syncfusion.com/downloads/support/directtrac/general/ze/SampleWF920548313)
107+
You can find the complete sample in the [Github](https://github.com/SyncfusionExamples/WinForms-PDFViewer-Examples/tree/master/How-to/Host-WPFPdfViewer-in-Winforms/HostedPdfViewer) for your reference.

0 commit comments

Comments
 (0)