Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error in simple application
Message
From
10/12/2008 09:57:22
 
 
To
09/12/2008 14:57:51
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01366277
Message ID:
01366439
Views:
7
>I created my first 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);
>        }
>    }
>}
>
Hi,

I think the problem is probably in the c# constructor code for Page1 but it's not possible to say where since you don't show code for WindowsFormsHost or mainForm (if you chop out all of the constructor code except InitializeComponent it compiles OK)
Regards,
Viv
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform