GdViewer with WPF

Example requests & Code samples for GdPicture Toolkits.
Post Reply
euclidez
Posts: 2
Joined: Sat Oct 25, 2008 5:05 pm

GdViewer with WPF

Post by euclidez » Fri Oct 31, 2008 9:56 pm

Hi. Anybody know a way to use the viewer inside a WPF Window?

Thanks a lot.

dcreeron
Posts: 35
Joined: Tue Apr 14, 2009 7:55 pm
Location: Apex, NC
Contact:

Re: GdViewer with WPF

Post by dcreeron » Fri Aug 20, 2010 7:54 am

1) Add a reference to the GdPicture.NET.dll to your project.

2) Wrap the GdViewer in a WindowsFormsHost like so:

Code: Select all

<Window
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:local="clr-namespace:PaperValet"
    xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    xmlns:gdPicture="clr-namespace:GdPicture;assembly=GdPicture.Net"
	mc:Ignorable="d"
	x:Class="PaperValet.MainWindow"
	x:Name="Window"
	Title="MainWindow"
	Width="640" Height="480">

	<DockPanel LastChildFill="True">
		<Menu DockPanel.Dock="Top">
			<MenuItem Header="MenuItem"/>
		</Menu>
		<ToolBarTray DockPanel.Dock="Top">
			<ToolBar/>
		</ToolBarTray>
	    <StatusBar DockPanel.Dock="Bottom">
	    	<TextBlock><Run Text="Status Bar"/></TextBlock>
	  	</StatusBar>
		<StackPanel DockPanel.Dock="Left">
			<Button Content="AccountsHere"/>
		</StackPanel>
[b]        <WindowsFormsHost Margin="5" Grid.Row="0">
            <gdPicture:GdViewer x:Name="gdViewer" BackColor="Aquamarine"></gdPicture:GdViewer>
        </WindowsFormsHost>[/b]

    </DockPanel>

</Window>
3) Then in your code-behind do something like this:

Code: Select all

		public MainWindow()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
            if (gdViewer != null)
            {
                bool result = gdViewer.SetLicenseNumber("XXX");  // Replace with your key!
                string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                GdPictureStatus status = gdViewer.DisplayFromFile(
                    System.IO.Path.Combine(System.IO.Path.GetDirectoryName(exePath), "TestImage.png"));
                if (status == GdPictureStatus.OK)
                {
                    gdViewer.MouseMode = ViewerMouseMode.MouseModePan;
                    gdViewer.ScrollBars = true;
                    int pageCount = gdViewer.PageCount;
                }
            }
        }

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest