Proper usage (best practices) of Browsable attribute in .NET for runtime grid component behavior
I understand how Browsable attribute开发者_如何转开发 is supposed to work. It's supposed to hide a property from showing up in a PropertyGrid in design time.
It also has another effect in that it will stop a Property from showing up in components such as Grids, or specifically Infragistics WinGrid. I am not sure if it has this behaviour on regular Windows Forms grids.
This works, but it doesn't sound like Browsable is being use as intended when being used for 'Run time' displaying of a property on a grid component.
Any literature from Microsoft on proper use. Even though it works, I don't want to use this attribute to hide columns on a grid bound to a business object if it's not indeed the correct usage of the attribute, but rather something some grid vendors decided to use to determine property visibility on their grids.
There is no rule in the .NET Framework Guidelines that says that attributes should be exclusive to the kind of types for which it was designed or commonly used. Re-using them certainly helps the programmer having to memorize less class names, as long as s/he doesn't have to jump through hoops with using/Imports directives and assembly references. Not an issue with a Windows Forms control.
Giving an attribute runtime behavior when it normally gets used to affect design-time behavior wouldn't be my choice however. It's Infragistics, what can I say...
The Microsoft "Browsable" attribute has nothing to do with hiding Grid columns.
It just specifies whether a property should be displayed in a Properties window of the Visual Studio Designer(or also PropertyGrid component). Members marked with the BrowsableAttribute to false are not appropriate for design-time editing and therefore are not displayed in a visual designer.
This is all about this attribute. We can't speack about "best practices" here, is like we discuss the best practices for the "Visible" button property.
精彩评论