我该怎么做才能使我的子派生自定义控件出现在混合资源库中?
我正在基于 CodePlex 上提供的出色的 Mockups 库 创建一系列窗口模型模板。
我也使用他们的 BaseMockup 作为我的控件的基础,并且我遵循了列出的步骤的相同概要 here 用于从现有控件进行子派生(创建一个新的空类,将默认样式添加到 /Themes/generic.xaml 等)
该控件正在工作太棒了 - 唯一的问题是它没有出现在资产库中。我认为这是因为它是子派生的,或者因为我需要一些属性(相当于 WinForms 控件的 ToolboxItemAttribute ? ...这不起作用)以将其连接起来。
当我修改代码以直接从 Control 派生时,它会显示 - 不需要自定义属性。当然,这违背了我想做的事情的目的......
我唯一能找到的是 几个 文章 告诉我用注册表项进行修改,但没有一个是明确的,也没有建议使用 Blend 4 执行此操作的明确方法。最后一篇广告宣传为 Blend 4 技巧文章,但承认在最后它抄袭了其他两个(对于 Blend 3)的内容。
这是我唯一的选择 - 注册我的 DLL 吗?有更好的方法吗?
I am creating a series of window mockup templates based on the excellent Mockups library available on CodePlex.
I'm using their BaseMockup as the base for my control as well, and I followed the same outline of the steps listed here for sub-deriving from existing controls (Create a new empty class, add your default style to /Themes/generic.xaml, etc.)
The control is working great - the only thing is that it doesn't show up in the Assets library. I think this is because it's sub-derived, or because I need some attribute (the equivalent of the ToolboxItemAttribute for WinForms controls? ... which didn't work) to get it hooked up.
When I modify the code to derive directly from Control, it shows up - no custom attribute necessary. Of course that defeats the purpose of what I'm trying to do though...
The only thing I can find are several articles telling me to muck with registry keys, and none of them are clear or suggest a definitive way to do this with Blend 4. That last one advertises as a Blend 4 tips article, but admits at the end that it plagiarizes the content from the other two (for Blend 3).
Is that my only option - register my DLL? Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不久前,我写了一篇关于此的博客文章。我包含了一个 .reg 文件和一个 .bat 文件,用于设置寄存器和一些目录。我想这就是你正在寻找的。
A while ago I wrote a blogpost about this. I've included a .reg file and a .bat file for setting up the register and some directories. I think that's what you are looking for.
我相信你确实需要修改注册表项。具体来说,
32 位: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NET Framework\v4.0.30319\AssemblyFoldersEx
64 位: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NET Framework\v4.0.30319\AssemblyFoldersEx
使用控件名称创建一个新项集会。然后编辑该键下的默认字符串值,并将该值设置为安装控制组件的目录。 请参阅此处查看完整示例(使用 Silverlight 路径)。
I believe you do need to muck with registry keys. Specifically,
32 bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NET Framework\v4.0.30319\AssemblyFoldersEx
64 bit: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NET Framework\v4.0.30319\AssemblyFoldersEx
Create a new key with the name of your control assembly. Then edit the Default string value under this key and set the value to the directory where the control assemblies are installed. See here for a full example (using the Silverlight paths).
找到它 - 毕竟有一个模拟属性,它是 ToolboxBrowsableAttribute 。
你必须经过一些繁琐的操作才能设置它,但它工作得很好 - 不需要注册表清理。它需要创建一个设计器元数据提供程序类,对程序集进行归因,以便设计者可以发现它,然后将属性添加到元数据提供程序内的子派生控件中。
确保为您的 Visual Studio 版本选择适当的页面版本,因为界面在 2008 年和 2010 年间发生了很大变化
。 aspx?display=Print" rel="nofollow">CodeProject 上的这篇文章 有一些很好的、真实的设置示例。不过它们都是 2008 年的风格,所以如果您使用的是 2010 年的请记住这一点。
Found it - there is an analogue attribute after all, it's ToolboxBrowsableAttribute.
You have to go through a little more rigmarole to get it set up, but it works great - no registry mucking necessary. It requires creating a designer metadata provider class, attributing your assembly so it's designer-discoverable, and then adding the attributes to your sub-derived controls inside your metadata provider.
Make sure you choose the appropriate version of the page for your version of Visual Studio, because the interface changes a good bit between 2008 and 2010.
This article on CodeProject has some good, real-world examples of setting this up. They're all in the 2008 style though, so bear that in mind if you're using 2010.