Toadums
Toadums

Reputation: 2812

How to add a xaml page/usercontrol to a windows form control?

so basically what I am trying to do is create an input form in XAML, and add it to a panel in my C# wpf program.

What I am trying is:

Page pg = new Page();
Panel pnl = new Panel();

pnl.Controls.Add(pg);

But it gives me an error saying that it cannot convert a Page to Control...

I have tried the same thing with a xaml UserControl, with the same error.

Is there a way to do this?

Thanks!

Upvotes: 0

Views: 866

Answers (1)

krs1
krs1

Reputation: 1135

Page is a root element, you can't add any parent elements to a Page object. Also make sure to define an XML namespace to go with that Page element.

I think you're imagining it in the wrong terms. Think of the Page element as the encompassing web page itself. A page can be divided into panels which control the layout of the page itself.

Also keep in mind that the Panel class itself is only a base class. Use one of the derived classes in order to get the layout you want.

Upvotes: 2

Related Questions