开发者

Visual Studio Designer keeps trying to initialize my Collection property

I've created a UserControl called CatalogBrowser which has a property ListedFamilies that exposes the currently listed Family objects in the control. Here's the code for the property.

public List<Family> ListedFamilies {
     get {
         List<Family> returnList = new List<Family>();
         foreach (Object obj in this.familyObjectListView.Objects) {
             returnList.Add((Family)obj);
         }
         return returnList;
     }
     set {
         this.familyObjectListView.ClearObjects();
         this.familyObjectListView.Objects = value;
     }
 }

Now in a Form where I am using this control I keep having a problem with Visual Studio adding the following line in the Form's designer file.

this.catalogBrowserControl1.ListedFamilies = ((System.Collections.Generic.List<SOMLib.Family>)(resources.GetObject("catalogBrowserControl1.ListedFamilies")));

This causes my program to crash because I don't have (or want) a开发者_如何学编程 resource in my project to initialize the value of this collection property.

How can I prevent Visual Studio from automatically trying to initialize this property?


One trick is to add the [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] attribute to your property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜