0
在SL5中,我有一個DataForm,它顯示來自實體模型生成的DomainService.metadata的數據。DataAnnotations.EnumDataTypeAttribute在Silverlight中不起作用
我使用DataAnnotation.ValidationAttribues(如Required,StringLength等)來裝飾DomainService.metadata中的數據屬性。
這些驗證屬性工作得很好,一旦我編譯並運行,驗證存在於DataForm中。
但我不能讓EnumDataType屬性的數據形的工作,就好像它不存在:
public partial class Student {
internal sealed class StudentMetadata {
public enum MyEnum {
One = 1,
Two = 2
}
private StudentMetadata() {
}
[EnumDataType(typeof(MyEnum), ErrorMessage = "Type 1 or 2")]
public Nullable<int> Other { get; set; }
[Required]
public int Age { get; set; }
例如,在數據形的場年齡不能留空,但如果我在TypeOfRoom字段中輸入4,則不會顯示錯誤消息。
我知道我可以使用組合框或其他東西,但我想了解EnumDataType驗證屬性的用法。
謝謝你的回答。它不符合你的建議。當我輸入一個枚舉之外的值時,DataForm不會引發任何錯誤。 – user1462071
@ user1462071:我認爲您需要使用ComboBox來選擇可能的枚舉值,而不是用於輸入值的TextBox。 – Jehof