{"record":{"id":"c2b3ea77414a5562","repo":"MahApps/MahApps.Metro","slug":"template-part-templatepart-in-template-for-t-c2b3ea","errorCode":null,"errorMessage":"Template part \"{templatePart}\" in template for \"{target.GetType().FullName}\" is missing.","messagePattern":"Template part \"(.+?)\" in template for \"(.+?)\" is missing\\.","errorType":"exception","errorClass":"MissingRequiredTemplatePartException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/RangeSlider.cs","lineNumber":1315,"sourceCode":"            this.ReCalculateRangeSelected(true, true, this._direction);\n            this.CoerceLowerUpperValues();\n        }\n\n        public void ResetSelection(bool isStart)\n        {\n            var widthChange = this.Maximum - this.Minimum;\n            widthChange = isStart ? -widthChange : widthChange;\n\n            MoveThumb(this._leftButton, this._rightButton, widthChange, this.Orientation, out this._direction);\n            this.ReCalculateRangeSelected(true, true, this._direction);\n            this.CoerceLowerUpperValues();\n        }\n\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            this._container = this.GetTemplateChild(\"PART_Container\") as FrameworkElement ?? throw new MissingRequiredTemplatePartException(this, \"PART_Container\");\n            this._visualElementsContainer = this.GetTemplateChild(\"PART_RangeSliderContainer\") as StackPanel ?? throw new MissingRequiredTemplatePartException(this, \"PART_RangeSliderContainer\");\n            this._centerThumb = this.GetTemplateChild(\"PART_MiddleThumb\") as Thumb ?? throw new MissingRequiredTemplatePartException(this, \"PART_MiddleThumb\");\n            this._leftButton = this.GetTemplateChild(\"PART_LeftEdge\") as RepeatButton ?? throw new MissingRequiredTemplatePartException(this, \"PART_LeftEdge\");\n            this._rightButton = this.GetTemplateChild(\"PART_RightEdge\") as RepeatButton ?? throw new MissingRequiredTemplatePartException(this, \"PART_RightEdge\");\n            this._leftThumb = this.GetTemplateChild(\"PART_LeftThumb\") as Thumb ?? throw new MissingRequiredTemplatePartException(this, \"PART_LeftThumb\");\n            this._rightThumb = this.GetTemplateChild(\"PART_RightThumb\") as Thumb ?? throw new MissingRequiredTemplatePartException(this, \"PART_RightThumb\");\n\n            this.InitializeVisualElementsContainer();\n            this.ReCalculateSize();\n        }\n\n        //adds visual element to the container\n        private void InitializeVisualElementsContainer()\n        {\n            this._leftThumb.DragCompleted -= this.LeftThumbDragComplete;\n            this._rightThumb.DragCompleted -= this.RightThumbDragComplete;\n            this._leftThumb.DragStarted -= this.LeftThumbDragStart;\n            this._rightThumb.DragStarted -= this.RightThumbDragStart;","sourceCodeStart":1297,"sourceCodeEnd":1333,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/RangeSlider.cs#L1297-L1333","documentation":"Thrown by RangeSlider.OnApplyTemplate when GetTemplateChild('PART_Container') does not return a FrameworkElement. MissingRequiredTemplatePartException fires because the slider's layout logic depends on this container for measuring and arranging the thumb/track elements.","triggerScenarios":"Custom ControlTemplate for RangeSlider missing a FrameworkElement named 'PART_Container'. Default MahApps theme not applied due to missing resource dictionaries.","commonSituations":"Custom RangeSlider template without the required parts. MahApps theme dictionaries not merged in App.xaml. Generic style hiding the default template.","solutions":["Merge MahApps.Metro theme resources so the default RangeSlider template is applied.","If re-templating, include a FrameworkElement named 'PART_Container'.","Verify the control resolves its default style from the MahApps themes."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var container = slider.Template?.FindName(\"PART_Container\", slider) as FrameworkElement;\nif (container == null) throw new InvalidOperationException(\"RangeSlider missing PART_Container\");","typeGuard":null,"tryCatchPattern":"try\n{\n    slider.ApplyTemplate();\n}\ncatch (MahAppsException ex) when (ex.Message.Contains(\"PART_Container\"))\n{\n    // load default theme\n}","preventionTips":["Merge MahApps theme dictionaries.","Include all required PART_ elements in custom RangeSlider templates.","Verify default style resolution at design time."],"tags":["wpf","mahapps","template","control-template","rangeslider","resource-dictionary"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}