{"record":{"id":"6b26a0f02c07991e","repo":"dotnet/maui","slug":"element-must-be-of-type-slider","errorCode":null,"errorMessage":"Element must be of type Slider.","messagePattern":"Element must be of type Slider\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Material/src/Android/MaterialSliderRenderer.cs","lineNumber":191,"sourceCode":"\t\t}\n\n\t\t// SeekBar.IOnSeekBarChangeListener\n\t\tvoid SeekBar.IOnSeekBarChangeListener.OnProgressChanged(SeekBar seekBar, int progress, bool fromUser)\n\t\t{\n\t\t\tif (fromUser)\n\t\t\t\t((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, Value);\n\t\t}\n\n\t\tvoid SeekBar.IOnSeekBarChangeListener.OnStartTrackingTouch(SeekBar seekBar) => ((ISliderController)Element)?.SendDragStarted();\n\n\t\tvoid SeekBar.IOnSeekBarChangeListener.OnStopTrackingTouch(SeekBar seekBar) => ((ISliderController)Element)?.SendDragCompleted();\n\n\t\t// IVisualElementRenderer\n\t\tVisualElement IVisualElementRenderer.Element => Element;\n\t\tVisualElementTracker IVisualElementRenderer.Tracker => _visualElementTracker;\n\t\tAView IVisualElementRenderer.View => this;\n\t\tvoid IVisualElementRenderer.SetElement(VisualElement element) =>\n\t\t\tElement = (element as Slider) ?? throw new ArgumentException($\"Element must be of type {nameof(Slider)}.\");\n\t\tvoid IVisualElementRenderer.UpdateLayout() =>\n\t\t\t_visualElementTracker?.UpdateLayout();\n\n\t\tSizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)\n\t\t{\n\t\t\tMeasure(widthConstraint, heightConstraint);\n\t\t\treturn new SizeRequest(new Size(Control.MeasuredWidth, Control.MeasuredHeight), new Size());\n\t\t}\n\n\t\tvoid IVisualElementRenderer.SetLabelFor(int? id)\n\t\t{\n\t\t\tif (_defaultLabelFor == null)\n\t\t\t\t_defaultLabelFor = ViewCompat.GetLabelFor(this);\n\n\t\t\tViewCompat.SetLabelFor(this, (int)(id ?? _defaultLabelFor));\n\t\t}\n\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Material/src/Android/MaterialSliderRenderer.cs#L173-L209","documentation":"MaterialSliderRenderer renders Material Design Slider elements on Android. SetElement casts the VisualElement to Slider and throws ArgumentException on type mismatch. The renderer wires SeekBar change listeners and reads Slider.ValueProperty, all of which require a Slider element.","triggerScenarios":"A non-Slider element is dispatched to MaterialSliderRenderer through incorrect registration. Occurs when custom stepper or range controls are accidentally mapped to the Slider renderer.","commonSituations":"Confusing Slider with Stepper in ExportRenderer mappings. Custom range controls registered against MaterialSliderRenderer without deriving from Slider. Stale registrations after refactoring.","solutions":["Verify ExportRenderer maps Slider to MaterialSliderRenderer.","Ensure custom slider-like controls derive from Slider if they use this renderer.","Audit for conflicting Slider registrations across all referenced assemblies.","If migrating, update both element and renderer types together."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(Stepper), typeof(MaterialSliderRenderer))]\n\n// after\n[assembly: ExportRenderer(typeof(Slider), typeof(MaterialSliderRenderer))]","handlingStrategy":"type-guard","validationCode":"if (element is not Slider)\n    throw new InvalidOperationException($\"Expected Slider, got {element?.GetType().Name}\");\nrenderer.SetElement(element);","typeGuard":"static bool IsSlider(VisualElement? element) => element is Slider;","tryCatchPattern":null,"preventionTips":["Distinguish Slider from Stepper in ExportRenderer mappings.","Ensure custom slider controls derive from Slider.","Audit for conflicting Slider registrations across assemblies."],"tags":["maui","android","material","renderer","type-mismatch","slider"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}