{"record":{"id":"76c4a66b0291d785","repo":"dotnet/maui","slug":"enumpicker-enumtype-property-must-be-enumeration-76c4a6","errorCode":null,"errorMessage":"EnumPicker: EnumType property must be enumeration type","messagePattern":"EnumPicker: EnumType property must be enumeration type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ScrollModeGalleries/EnumPicker.cs","lineNumber":22,"sourceCode":"\nnamespace Maui.Controls.Sample.Pages.CollectionViewGalleries.ScrollModeGalleries\n{\n\tclass EnumPicker : Picker\n\t{\n\t\tpublic static readonly BindableProperty EnumTypeProperty =\n\t\t\tBindableProperty.Create(nameof(EnumType), typeof(Type), typeof(EnumPicker),\n\t\t\t\tpropertyChanged: (bindable, oldValue, newValue) =>\n\t\t\t\t{\n\t\t\t\t\tEnumPicker picker = (EnumPicker)bindable;\n\n\t\t\t\t\tif (oldValue != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tpicker.ItemsSource = null;\n\t\t\t\t\t}\n\t\t\t\t\tif (newValue != null)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (!((Type)newValue).GetTypeInfo().IsEnum)\n\t\t\t\t\t\t\tthrow new ArgumentException(\"EnumPicker: EnumType property must be enumeration type\");\n\n\t\t\t\t\t\tpicker.ItemsSource = Enum.GetValues((Type)newValue);\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\tpublic Type EnumType\n\t\t{\n\t\t\tset => SetValue(EnumTypeProperty, value);\n\t\t\tget => (Type)GetValue(EnumTypeProperty);\n\t\t}\n\t}\n}\n","sourceCodeStart":4,"sourceCodeEnd":35,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/samples/Controls.Sample/Pages/Controls/CollectionViewGalleries/ScrollModeGalleries/EnumPicker.cs#L4-L35","documentation":"This is a second copy of the EnumPicker sample used in CollectionView gallery pages. It has identical logic: the EnumType bindable property's propertyChanged callback rejects non-enum Types with ArgumentException because the picker populates its ItemsSource via Enum.GetValues, which requires an actual enumeration.","triggerScenarios":"Assigning a non-enum Type to this EnumPicker's EnumType property. Occurs when binding EnumType to a gallery option backed by a non-enum type, or programmatically setting it incorrectly.","commonSituations":"Sample/gallery code that binds EnumType to a loosely-typed property. Copy-paste of the EnumPicker into a new gallery without verifying the bound type is an enum. Type resolution issues from reflection or dynamic code.","solutions":["Ensure only enum types are assigned: `picker.EnumType = typeof(ScrollMode);`","Guard before assignment: `if (candidateType.GetTypeInfo().IsEnum) picker.EnumType = candidateType;`","If binding, constrain the source property to return only enum Types."],"exampleFix":"// before\npicker.EnumType = typeof(string);\n\n// after\npicker.EnumType = typeof(ScrollMode);","handlingStrategy":"validation","validationCode":"var candidateType = typeof(ScrollMode);\nif (candidateType.GetTypeInfo().IsEnum)\n    picker.EnumType = candidateType;","typeGuard":"static bool IsEnumType(Type? type) => type?.GetTypeInfo().IsEnum ?? false;","tryCatchPattern":null,"preventionTips":["Bind EnumType only to properties that return enum Types.","Validate IsEnum before assignment in gallery/sample code.","Add unit tests for EnumPicker covering both enum and non-enum assignments."],"tags":["maui","controls","picker","enum","argument","validation","sample","collectionview"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}