如何让Visual Studio.net 2003 智能感知自定义属性
有时候我们开发了一个web框架,并且这个框架需要给控件加入框架特有的属性才能正确运行,但是vs.net不能够智能感知这些新的属性,在新属性比较多时,就会给开发带来一定的麻烦。怎样才能让vs.net识别这些新的属性呢?
可以通过修改 <Visual Studio installation folder>\Common7\Packages\schemas\xml\asp.xsd 文件,来达到我们的目的。
效果如下图:
例如,想让asp:CheckBox 增加 zbind属性,先找到asp:CheckBox的定义,如下:
<!-- <asp:CheckBox> -->
<xsd:complexType name="CheckBoxDef" vs:noambientcontentmodel="true">
<xsd:attribute name="AutoPostBack" type="xsd:boolean" />
<xsd:attribute name="Checked" type="xsd:boolean" />
<xsd:attribute name="Text" type="xsd:string" />
<xsd:attribute name="TextAlign" type="TextAlign" />
<xsd:attribute name="OnCheckedChanged" vs:omtype="event" />
<xsd:attribute name="Enabled" type="xsd:boolean" />
<xsd:attribute name="BorderWidth" type="ui4" />
<xsd:attribute name="BorderColor" type="xsd:string" vs:builder="color" />
<xsd:attribute name="BorderStyle" type="BorderStyle" />
<xsd:attributeGroup ref="WebControlAttributes" />
</xsd:complexType>
<xsd:attribute name="zbind" type="xsd:string"/>
如果按这种方法修改,我们自定义的标签就可以得到智能提示,Web框架的用户将会得到更好的易用性。
另外,也可以定义枚举类型,下面定义的是HorizontalAlign类型,智能提示为:
<xsd:attributeGroup name="TableCellAttributes">
<xsd:attribute name="VerticalAlign" type="VerticalAlign" />
<xsd:attribute name="RowSpan" type="xsd:integer" />
<xsd:attribute name="ColumnSpan" type="xsd:integer" />
<xsd:attribute name="HorizontalAlign" type="HorizontalAlign" />
….
</xsd:attributeGroup>

<xsd:simpleType name="HorizontalAlign">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="NotSet" />
<xsd:enumeration value="Left" />
<xsd:enumeration value="Center" />
<xsd:enumeration value="Right" />
<xsd:enumeration value="Justify" />
</xsd:restriction>
</xsd:simpleType>


浙公网安备 33010602011771号