Вопрос

I understand that whenever you create a property for a user control, you can set the property value through declarative syntax, so you can have something like this:

<uc1:MyControl id="MyControl1" runat="server" Text="Hello" Number="10" Access="ReadWrite" />

These attributes set the value for properties of type:

  • Text is String
  • Number is Integer
  • Access is Enum

I wouldn't be able to set a public property of type "Array" or "Control" in declarative markup. (or can I?)

My question is:

What is the complete list of Types that can be set directly with declarative syntax as attributes in a control?

Это было полезно?

Решение

Ok, after some time with this question without being solved, finally I found the official answer in this article at the MSDN library.

Turns out that those properties that can be persisted as attributes are called Simple Properties and must be a string or a type that easily maps to a string. Here's an extract of the article:

" A simple property is a property whose type is a string or a type that maps easily to a string. A simple property is persisted as an attribute on the control's opening tag without any work on your part. Properties of type String and primitive value types in the .NET Framework class library such as Boolean, Int16, Int32, and Enum are simple properties. "

So I had the list almost complete in my question. Properties that can be set directly with declarative syntax (as atributes) must be of the following types:

  • String
  • Boolean
  • Int16
  • Int32
  • Enum
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top