为什么 C# 窗口应用程序中的 Designer 中 IExtenderProvider 属性丢失?
我已经为控件创建了一个 IExtenderProvider (扩展器)。使用 Extender ,我正在迭代控件集合并验证它。它工作得很好。但是,有时在更改某些设计时,或者当设计器刷新时(同时从代码中删除一些事件) ,扩展器提供的属性(验证顺序和组,在我的例子中)正在从设计器中丢失,并且控件本身没有添加到扩展器集合中。所以,应用程序完成的验证崩溃了(并且当然,应用程序本身)。我在 IExtenderProvider 中也有 ShouldSerialize 和 Reset 方法。但没有任何帮助我。请指导我如何使所有控件始终对扩展程序可见。
谢谢, 马蒂
I have created a IExtenderProvider (Extender) for Controls.using Extender ,I am Iterating the collection of controls and validate it.It works fine.but, some time while changing some designs,or when designer refreshed (while removing some events from code), the properties that provided by Extender (Validation Order and Group,in my case) are getting lost from designer and the control itself is not added into Extender collection.so, The validation done by application collapsed (and, of course, application itself ).I have ShouldSerialize and Reset Methods in IExtenderProvider too.but nothing helped me.Please guide me how make all controls visible to extender at all times.
Thanks,
Mathi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当Extender出现异常时,有时会发生这种情况。 如果发生这种情况,您将需要在设计时调试扩展器。 今天我不得不这样做好几次。 查看调试设计时控件,它应该可以帮助您
入门有时会发生这种情况,因为您更改了扩展器的属性和方法,并且“序列化”值不再合适。
This sometimes happens when there is an exception in the Extender. If this happens, you will need to debug your extender in design-time. I had to do this several times today. Check out Debugging Design-Time Controls, it should get you started
Other times this happens because you have changed properties and methods of the Extender and the "serialize" values are no longer appropriate.
本文标题为“
Stack Overflow 上的另一个答案也引用了本文中的大部分相关信息。
This article titled "Bending the code generation of IExtenderProvider to your will" by Tim Van Wassenhove may have a solution that is related to your problem. It describes building a custom serializer for your IExtenderProvider implementation which, in doing so may alleviate the issue stated here.
Most of the relevant information from the article was also quoted in another answer here on Stack Overflow.
以下答案对于OP来说绝对是迟到的,但可能对其他人有帮助。
我遇到了同样的问题:财产要么丢失,要么根本没有出现。 就我而言,问题是,使用 ProvideProperty、CanExtend 以及 SetXXX 和 GetXX 方法指定的类型不相同。 例如,ProvideProperty 和 CanExtend 指定“Control”作为类型,但 SetXXX 和 GetXXX 方法指定“object”作为第一个参数。
因此,一旦我确定,对于 ProvideProperty 中指定的每种类型,我都有一个匹配的 GetXXX 和 SetXXX,一切都会按预期工作。
也许这有帮助。
注意:修复代码后,我必须重新启动 Visual Studio。
The following answer is definetly to late for the OP, but might help others.
I had the same problem: properties were either lost or didn't show up at all. In my case the problem was, that the type specified with ProvideProperty, CanExtend and the SetXXX and GetXX methods were not the same. For example ProvideProperty and CanExtend specified 'Control' as type, but the SetXXX and GetXXX mehtods specified 'object' as first parameter.
So, as soon as I made sure, that for each and every type specified in ProvideProperty I had a matching GetXXX and SetXXX, everything worked as expected.
Maybe this helps.
Note: After fixing the code I had to restart Visual Studio.