{"record":{"id":"c1074c62fae78654","repo":"MahApps/MahApps.Metro","slug":"you-have-missed-to-specify-part-numericup-part-nu","errorCode":null,"errorMessage":"You have missed to specify PART_NumericUp, PART_NumericDown or PART_TextBox in your template!","messagePattern":"You have missed to specify PART_NumericUp, PART_NumericDown or PART_TextBox in your template!","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/NumericUpDown.cs","lineNumber":1008,"sourceCode":"            }\n        }\n\n        /// <summary>\n        ///     When overridden in a derived class, is invoked whenever application code or internal processes call\n        ///     <see cref=\"M:System.Windows.FrameworkElement.ApplyTemplate\" />.\n        /// </summary>\n        public override void OnApplyTemplate()\n        {\n            base.OnApplyTemplate();\n\n            this.repeatUp = this.GetTemplateChild(PART_NumericUp) as RepeatButton;\n            this.repeatDown = this.GetTemplateChild(PART_NumericDown) as RepeatButton;\n\n            this.valueTextBox = this.GetTemplateChild(PART_TextBox) as TextBox;\n\n            if (this.repeatUp is null || this.repeatDown is null || this.valueTextBox is null)\n            {\n                throw new InvalidOperationException($\"You have missed to specify {PART_NumericUp}, {PART_NumericDown} or {PART_TextBox} in your template!\");\n            }\n\n            this.ToggleReadOnlyMode(this.IsReadOnly);\n\n            this.repeatUp.Click += (_, _) => { this.ChangeValueWithSpeedUp(true); };\n            this.repeatDown.Click += (_, _) => { this.ChangeValueWithSpeedUp(false); };\n\n            this.repeatUp.PreviewMouseUp += (_, _) => this.ResetInternal();\n            this.repeatDown.PreviewMouseUp += (_, _) => this.ResetInternal();\n\n            this.OnValueChanged(this.Value, this.Value);\n\n            this.scrollViewer = null;\n        }\n\n        /// <summary>\n        /// Creates AutomationPeer (<see cref=\"UIElement.OnCreateAutomationPeer\"/>)\n        /// </summary>","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/NumericUpDown.cs#L990-L1026","documentation":"Thrown by NumericUpDown.OnApplyTemplate when any of PART_NumericUp, PART_NumericDown, or PART_TextBox is null after GetTemplateChild. Unlike the MissingRequiredTemplatePartException pattern used elsewhere, this is a plain InvalidOperationException with a combined message. The control requires RepeatButtons for up/down and a TextBox for value display.","triggerScenarios":"Custom ControlTemplate for NumericUpDown missing one or more of: a RepeatButton named 'PART_NumericUp', a RepeatButton named 'PART_NumericDown', or a TextBox named 'PART_TextBox'. Also if the default MahApps theme is not applied.","commonSituations":"Developer creates a custom NumericUpDown template without all three named elements. MahApps resource dictionaries not merged in App.xaml. Theme stripped or overridden by a generic style.","solutions":["Merge MahApps.Metro theme resources so the default NumericUpDown template (with all three parts) is applied.","If re-templating, include RepeatButton 'PART_NumericUp', RepeatButton 'PART_NumericDown', and TextBox 'PART_TextBox'.","Verify no other style hides the default template via BasedOn chains."],"exampleFix":"<!-- before -->\n<ControlTemplate TargetType=\"{x:Type controls:NumericUpDown}\">\n    <TextBox x:Name=\"PART_TextBox\"/>\n</ControlTemplate>\n\n<!-- after -->\n<ControlTemplate TargetType=\"{x:Type controls:NumericUpDown}\">\n    <Grid>\n        <TextBox x:Name=\"PART_TextBox\"/>\n        <RepeatButton x:Name=\"PART_NumericUp\" Content=\"+\"/>\n        <RepeatButton x:Name=\"PART_NumericDown\" Content=\"-\"/>\n    </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"// Ensure theme is applied\nvar up = numeric.Template?.FindName(\"PART_NumericUp\", numeric) as RepeatButton;\nvar down = numeric.Template?.FindName(\"PART_NumericDown\", numeric) as RepeatButton;\nvar box = numeric.Template?.FindName(\"PART_TextBox\", numeric) as TextBox;\nif (up == null || down == null || box == null)\n    throw new InvalidOperationException(\"NumericUpDown template is missing required parts\");","typeGuard":null,"tryCatchPattern":"try\n{\n    numeric.ApplyTemplate();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"PART_NumericUp\"))\n{\n    // load default MahApps theme\n}","preventionTips":["Merge MahApps.Metro theme dictionaries in App.xaml.","Include PART_NumericUp, PART_NumericDown, and PART_TextBox in custom NumericUpDown templates.","Verify the default style is not overridden by a generic implicit style."],"tags":["wpf","mahapps","template","control-template","numericupdown","resource-dictionary"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}