开发者

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

开发者 https://www.devze.com 2023-03-19 06:35 出处:网络
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.

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,开发者_Go百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消