调用WPF用户控件到扩展坞面板 [英] Calling a WPF user control to a dock panel

查看:51
本文介绍了调用WPF用户控件到扩展坞面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码领域的新手,并且一直在获取WPF UserControl的困扰,只需单击按钮即可在Dock面板中打开它.请帮忙.我可以使它在WinForm中工作,但对于WPF UserControl到停靠面板,相同的代码不起作用.

I m new to the coding scene and have been getting stuck on geting a WPF UserControl to open in a dock panel on a button click. Please help. I can get it to work in a WinForm but the same code doesn''t work for a WPF UserControl to a dock panel.

Dim obj1 As New UserControl1
obj1.AutoSize = True
obj1.AutoScroll = True
frmMain.pnlUser.Controls.Add(obj1)


上面的代码就是我在WinForms中用来调用WinForms UserControl的代码,它工作得很好.


the code above is what i was using in WinForms to call the WinForms UserControl and it worked just fine.

推荐答案

为什么您认为您的Forms代码可以在WPF中工作?这些库非常不同.

您需要执行以下操作:
Why would you think that your Forms code could work in WPF? These libraries are very different.

You need to do something like this:
Dim myUserControl As New MyUserControl

'...

myDockPanel.Children.Add(myUserControl)
DockPanel.SetDock(myUserControl, Dock.Bottom)



顺便说一句,请避免使用以下名称:obj1UserControl1.名称应具有语义;名称中没有数字;通常,观察者具有良好的Microsoft命名约定.

—SA



By the way, avoid those names: obj1, UserControl1. Names should be semantic; no numbers in names; in general, observer good Microsoft naming conventions.

—SA


这篇关于调用WPF用户控件到扩展坞面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆