我有使用以下属性的公共财产一个用户控件:
I have a UserControl with a public property using the following attributes:
[Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]我曾尝试删除所有者的形式,重新创建一个新的形成在Visual Studio 2010,并加入这个用户控件到窗体。它使加入像在设计文件中的以下行:
I have tried deleting the owner form, re-creating a fresh form in Visual Studio 2010, and adding this UserControl to the form. It keeps adding a line like the following in the Designer file:
this.vMyUserControl.MyProperty = ((MyNamespace.MyClass)(resources.GetObject("vMyUserControl.MyProperty")));这崩溃我的应用程序,因为这个属性的目的不是要通过序列化创建。
This crashes my application because this property is not designed to be created by serialization.
推荐答案我没能找到真正的解决办法,但有解决方法,而不是...
I failed to find a real solution, but a workaround instead...
我不得不进入Form.resx文件并找到数据/值密钥对,它正在反序列化到我的公共财产。我手动删除了对XML内容,然后我就能够运行应用程序。
I had to go into the Form.resx file and locate the data/value key pair that it was deserializing into my public property. I manually deleted the XML pair contents and then I was able to run the application.
这让我的应用程序构建和无差错运行。其他一切我试过(包括删除了我的用户,并多次重新创建它的容器的形式),没有工作。
This allowed my application to build and run without errors. Everything else I tried (including deleting the container form for my UserControl and re-creating it repeatedly) did not work.
更多推荐
使得Visual Studio设计忽略的公共属性
发布评论