error in simple xaml application

A

Andrus

I created simple winforms host xaml application containing one simple page.

Trying to run it causes error

System.Windows.Markup.XamlParseException was unhandled
Message: Cannot create instance of 'Page1' defined in assembly 'WPFHost,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been
thrown by the target of an invocation. Error in markup file 'Page1.xaml'
Line 1 Position 7.

There is no any other inforamtion available about this error.
How to fix?

Andrus.

Page1.xaml:

<Page x:Class="WPFHost.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
<Grid>
<StackPanel Margin="0,0,0,0" Name="stackPanel"
HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
</Page>




page1.xaml.cs:


using System.Windows.Controls;
using System.Windows.Forms.Integration;
using MyApp.UI;

namespace WPFHost
{
/// <summary>
/// Interaction logic for Page1.xaml
/// </summary>
public partial class Page1 : Page
{
private readonly MainForm mainForm = new MainForm();

public Page1()
{
InitializeComponent();

//Create a Windows Forms Host to host a form
WindowsFormsHost windowsFormsHost = new WindowsFormsHost();

stackPanel.Width = mainForm.Width;
stackPanel.Height = mainForm.Height;
windowsFormsHost.Width = mainForm.Width;
windowsFormsHost.Height = mainForm.Height;

mainForm.TopLevel = false;

windowsFormsHost.Child = mainForm;

stackPanel.Children.Add(windowsFormsHost);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top