简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM