如何使 WPF 自定义控件自动出现在 Visual Studio 工具箱中?
如果我创建 WPF 用户控件,它会自动显示在 Visual Studio 工具箱中。
有没有办法让其他控件自动出现在Visual Studio工具箱中?
相反,有没有办法从工具箱中隐藏用户控件?
If I create a WPF user control, it appears automatically in the Visual Studio toolbox.
Is there a way to make other controls appear automatically in the Visual Studio toolbox?
Conversely, is there a way to hide a user control from the toolbox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以右键单击工具箱并选择选择项目...,然后您将看到一个对话框,允许您选择要显示或隐藏的控件。
如果您想弄清楚如何为您提供控件的第三方执行此操作,请按照下面的评论查看这篇描述打包控件的 MSDN 文章:
http://msdn.microsoft.com/en-us/library/ms165358.aspx
You can right click on the toolbox and select Choose Items... Then from there you will get a dialog that allows you to select which controls to show or hide.
Per comment below if you are trying to figure out how to do this for a Third Party that you are providing your control to check out this MSDN article that describes packaging your control:
http://msdn.microsoft.com/en-us/library/ms165358.aspx
自动填充描述此处(最后),但总而言之,您可以将
DesignTimeVisible(false)
添加到您的 UserControl 以防止将其添加到工具箱。您的控件应该像您的 UserControls 一样添加,假设它们满足上面链接末尾的要求,即:
如果您正在构建可重用控件(最终用户只需添加对程序集的引用),那么您需要告诉 Visual Studio 它应该将您的控件加载到工具箱中。 这里有一个关于 WinForms 控件执行此操作的教程,但概念是相同的。可以找到 VSIX 安装程序教程 此处。
许多资源适用于旧版本的 Visual Studio,但同样的概念应该适用。您只需在适当的情况下更新版本信息即可。
Auto population is described here (at the end), but to summarize you can add
DesignTimeVisible(false)
to your UserControl to prevent it from being added to the Toolbox.Your controls should be added just like your UserControls, assuming they meet the requirements at the end of the link above, which are:
If you are building reusable controls (where your end-users will simply add a reference to your assembly), then you'd need to tell Visual Studio that it should load your controls into the Toolbox. There is a tutorial for WinForms controls on doing this here, but the concepts are the same. A VSIX installer tutorial can be found here.
A lot of the resources out there are for older versions of Visual Studio, but again the same concepts should apply. You simply need to update version information where appropriate.