{"id":21129503,"url":"https://github.com/guorg/gu.wpf.numericinput","last_synced_at":"2025-04-06T11:08:30.508Z","repository":{"id":23557841,"uuid":"26925281","full_name":"GuOrg/Gu.Wpf.NumericInput","owner":"GuOrg","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-06T08:14:23.000Z","size":2075,"stargazers_count":75,"open_issues_count":14,"forks_count":20,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T10:08:20.498Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GuOrg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-20T18:13:24.000Z","updated_at":"2025-03-16T01:37:43.000Z","dependencies_parsed_at":"2023-11-07T01:51:09.959Z","dependency_job_id":"19a74ac8-3235-49fa-93ba-f437c03b9e0b","html_url":"https://github.com/GuOrg/Gu.Wpf.NumericInput","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuOrg%2FGu.Wpf.NumericInput","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuOrg%2FGu.Wpf.NumericInput/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuOrg%2FGu.Wpf.NumericInput/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuOrg%2FGu.Wpf.NumericInput/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuOrg","download_url":"https://codeload.github.com/GuOrg/Gu.Wpf.NumericInput/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471520,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T05:23:58.663Z","updated_at":"2025-04-06T11:08:30.475Z","avatar_url":"https://github.com/GuOrg.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gu.Wpf.NumericInput\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n [![NuGet](https://img.shields.io/nuget/v/Gu.Wpf.NumericInput.svg)](https://www.nuget.org/packages/Gu.Wpf.NumericInput/)\n[![Build status](https://ci.appveyor.com/api/projects/status/e0nwl8lha4nsoxq7/branch/master?svg=true)](https://ci.appveyor.com/project/JohanLarsson/gu-wpf-numericinput/branch/master)\n[![ci](https://github.com/GuOrg/Gu.Wpf.NumericInput/actions/workflows/ci.yml/badge.svg)](https://github.com/GuOrg/Gu.Wpf.NumericInput/actions/workflows/ci.yml)\n[![Join the chat at https://gitter.im/JohanLarsson/Gu.Wpf.NumericInput](https://badges.gitter.im/JohanLarsson/Gu.Wpf.NumericInput.svg)](https://gitter.im/JohanLarsson/Gu.Wpf.NumericInput?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nTextboxes for numeric input in WPF.\n- DoubleBox\n- IntBox\n- DecimalBox\n- FloatBox\n- ShortBox\n- Easy to add more\n\n# Contents\n\n- [1. Samples](#1-samples)\n  - [1.1. Simple sample](#11-simple-sample)\n  - [1.2. Sample showing some of the properties](#12-sample-showing-some-of-the-properties)\n- [2. Features:](#2-features)\n- [3. Validation](#3-validation)\n  - [3.1. ValidationTrigger](#31-validationtrigger)\n  - [3.2. CanValueBeNull](#32-canvaluebenull)\n  - [3.3. MinValue](#33-minvalue)\n  - [3.4. MaxValue](#34-maxvalue)\n  - [3.5. NumberStyles](#35-numberstyles)\n  - [3.6. Culture](#36-culture)\n  - [3.7. RegexPattern](#37-regexpattern)\n- [4. Formatting](#4-formatting)\n  - [4.1. Culture](#41-culture)\n  - [4.1. NumberStyles](#41-numberstyles)\n  - [4.2 StringFormat](#42-stringformat)\n  - [4.3 DecimalDigits](#43-decimaldigits)\n- [5. Spinners](#5-spinners)\n  - [5.1. Increment](#51-increment)\n  - [5.2. AllowSpinners](#52-allowspinners)\n  - [5.3. IncrementCommand and DecrementCommand](#53-incrementcommand-and-decrementcommand)\n- [5. Attached properties](#5-attached-properties)\n  - [5.1. NumericBox](#51-numericbox)\n    - [5.1.1. NumericBox.Culture](#511-numericboxculture)\n    - [5.1.2. NumericBox.ValidationTrigger](#512-numericboxvalidationtrigger)\n    - [5.1.3. NumericBox.CanValueBeNull](#513-numericboxcanvaluebenull)\n    - [5.1.4. NumericBox.NumberStyles](#514-numericboxnumberstyles)\n    - [5.1.5. NumericBox.StringFormat](#515-numericboxstringformat)\n    - [5.1.6. NumericBox.DecimalDigits](#516-numericboxdecimaldigits)\n    - [5.1.7. NumericBox.AllowSpinners](#517-numericboxallowspinners)\n  - [5.2. Gu.Wpf.NumericInput.Select.TextBox](#52-guwpfnumericinputselecttextbox)\n    - [5.2.1. TextBox.SelectAllOnGotKeyboardFocus](#521-textboxselectallongotkeyboardfocus)\n    - [5.2.2. TextBox.SelectAllOnClick](#522-textboxselectallonclick)\n    - [5.2.3. TextBox.SelectAllOnDoubleClick](#523-textboxselectallondoubleclick)\n    - [5.2.4. TextBox.MoveFocusOnEnter](#524-textboxmovefocusonenter)\n  - [5.3 Gu.Wpf.NumericInput.Touch.TextBox](#53-guwpfnumericinputtouchtextbox)\n    - [5.3.1. TextBox.ShowTouchKeyboardOnTouchEnter](#531-textboxshowtouchkeyboardontouchenter)\n- [6. Style and Template keys](#6-style-and-template-keys)\n\n# 1. Samples\n    \n## 1.1. Simple sample\nThe `Text`property is used internally and will throw if you bind to it.\n\nBind the `Value`property of the boxes like this:\n```xaml\n\u003cnumericInput:DoubleBox Value=\"{Binding DoubleValue}\" /\u003e\n```\n\n## 1.2. Sample showing some of the properties\n```xaml\n\u003cnumeric:SpinnerDecorator\u003e\n    \u003cnumeric:DoubleBox Value=\"{Binding Value,\n                                       ValidatesOnNotifyDataErrors=True}\" \n                       CanValueBeNull=\"{Binding CanValueBeNull}\"\n                       ValidationTrigger=\"PropertyChanged\"\n                       MaxValue=\"10\"\n                       MinValue=\"-10\"\n                       NumberStyles=\"AllowDecimalPoint,AllowLeadingSign\"\n                       RegexPattern=\"\\1\\d+(\\.2\\d+)\"\n                       StringFormat=\"N2\"\n                       AllowSpinners=\"True\"\n                       SpinUpdateMode=\"PropertyChanged\"\n                       Increment=\"{Binding Increment}\"/\u003e\n\u003c/numeric:SpinnerDecorator\u003e\n```\n\n# 2. Features:\n- Validation\n  - Validates as you type even with UpdateSourceTrigger=LostFocus for the binding. Configurable via `ValidationTrigger`\n  - Uses vanilla WPF validation\n  - If there is a validation error no value is sent to the viewmodel.\n- Works with WPF focus.\n- Formatting using formatted view and edit view.\n- Compatible with WPF undo/redo.\n- SpinnerDecorator for up/down buttons.\n\n![render](http://i.imgur.com/ru5TESv.gif)\n\n# 3. Validation\n\n## 3.1. ValidationTrigger\nControl when validation is performed, the default is `LostFocus` to be consistent with vanilla WPF `TextBox`\nSetting `ValidationTrigger=\"PropertyChanged\"` validates as you type even if the binding has `UpdateSourceTrigger=LostFocus`.\nAvailable as inheriting attached property: `NumericBox.ValidationTrigger`\n\n## 3.2. CanValueBeNull\nSets if empty textbox sends null to the binding source and is a legal value. Useful when binding to a `double?` for example.\nAvailable as inheriting attached property: `NumericBox.CanValueBeNull`\n\n## 3.3. MinValue\nThe minimum value. The default is null meaning that no validation on min is performed.\nWhen using spinners clicking decrease truncates to min if it would decrement below min.\nIf user enters a value less than `MinValue` the validation returns an `IsLessThanValidationResult`\nWith the content as a string `Properties.Resources.Please_enter_a_value_greater_than_or_equal_to__0__`\nThe message is localized using `box.Culture`.\n\n## 3.4. MaxValue\nThe maximum value. The default is null meaning that no validation on max is performed.\nWhen using spinners clicking increase truncates to max if it would increment above max.\nIf user enters a value greater than `MaxValue` the validation returns an `IsGreaterThanValidationResult`\nWith the content as a string `Properties.Resources.Please_enter_a_value_less_than_or_equal_to__0__`\nThe message is localized using `box.Culture`.\n\n## 3.5. NumberStyles\nThe `NumberStyles` used when parsing and formatting the value.\nEx if you want to allow leading sign or thousands.\n\n## 3.6. Culture\nThe `IFormatProvider` used when parsing and formatting the value.\nThe default value for culture is `Thread.CurrentThread.CurrentUICulture`\nAvailable as inheriting attached property: `NumericBox.Culture`\n\n## 3.7. RegexPattern\nA regex pattern used when validating the input.\n\n# 4. Formatting\n\nIf `StringFormat`or `DecimalDigits` are specified a TextBlock with the formatted text is overlaid when not focused.\n\n## 4.1. Culture\nThe `IFormatProvider` used when parsing and formatting the value.\nThe default value for culture is `Thread.CurrentThread.CurrentUICulture`\nAvailable as inheriting attached property: `NumericBox.Culture`\n\n## 4.1. NumberStyles\nThe `NumberStyles` used when parsing and formatting the value.\n\n```xaml\n\u003cnumeric:DoubleBox NumberStyles=\"AllowDecimalPoint, AllowLeadingSign\"\n                   Value=\"{Binding Value}\" /\u003e\n```\n\n## 4.2 StringFormat\nThe string format used in the formatted view.\n\nAvailable as inheriting attached property: `NumericBox.StringFormat`\n\n```xaml\n\u003cnumeric:DoubleBox Culture=\"sv-se\"\n                   StringFormat=\"#,0.00\"\n                   Value=\"{Binding Value}\" /\u003e\n```\n\n## 4.3 DecimalDigits\n`DecimalDigits=\"3\"` sets stringformat to `F3` which means the value will always have three digits.\n\n`DecimalDigits=\"-3\"` sets stringformat to `0.###` which means the value will be rendered with up to three digits.\n\nIf the user eneters more digits they are used in the Value binding. The formatted view will round the value.\n\nAvailable as inheriting attached property: `NumericBox.DecimalDigits`\n\n# 5. Spinners\nIf you want to add up/down buttons you wrap the box in a spinnerdecorator liken this:\n\n```xaml\n\u003cnumeric:SpinnerDecorator\u003e\n    \u003cnumeric:DoubleBox AllowSpinners=\"True\"\n                       Increment=\"10\"\n                       Value=\"{Binding Value}\" /\u003e\n\u003c/numeric:SpinnerDecorator\u003e\n```\n\nThe spinner decorator derives from `Control` so it can be templated for easy styling.\n\n## 5.1. Increment\nHow big change each increment/decrement is. Checked for overflow.\nIf the value is 9.5 and `Increment=\"1\"`and `Max=\"10\"` one click on increment will set the value to 10. \n\n## 5.2. AllowSpinners\nControls if spinners are visible assuming the control is wrapped in a `SpinnerDecorator`\n\n## 5.3. SpinUpdateMode\nControls how the `IncreaseCommand` and the `DecreaseCommand`behaves.\nThe default is `AsBinding` meaning the value updates using the `UpdateSourceTrigger` specified in the binding. Default is lostfocus.\nIf set to `PropertyChanged` the binding source will be updated at each click even if the binding has `UpdateSourceTrigger = LostFocus`\nThis property inherits so it can be set for example on the `Window` ex: `numericInput:NumericBox.SpinUpdateMode = \"PropertyChanged\"`\n\n## 5.4. IncrementCommand and DecrementCommand\nThe boxes exposes two command for incrementing and decrementing the current value with `Increment` clicking changes the text so it is undoable.\n\n\n\n# 5. Attached properties\n## 5.1. NumericBox\n### 5.1.1. NumericBox.Culture\nControls what Culture to use.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.Culture=\"sv-se\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.2. NumericBox.ValidationTrigger\nControls when validation is performed.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.ValidationTrigger=\"PropertyChanged\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.3. NumericBox.CanValueBeNull\nControls if empty means null and is a legal value.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.CanValueBeNull=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.4. NumericBox.NumberStyles\nControls if empty means null and is a legal value.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.NumberStyles=\"AllowDecimalPoint, AllowLeadingSign\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.5. NumericBox.StringFormat\nControls how many decimal digits are shown.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.StringFormat=\"F2\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.6. NumericBox.DecimalDigits\nControls how many decimal digits are shown.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `DecimalDigitsBox\u003cT\u003e`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.DecimalDigits=\"-2\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.1.7. NumericBox.AllowSpinners\nAllows spinners on all child NumericBoxes.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `BaseBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:numeric=\"http://gu.se/NumericInput\"\u003e\n    \u003cGrid numeric:NumericBox.AllowSpinners=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cnumeric:DoubleBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n## 5.2. Gu.Wpf.NumericInput.Select.TextBox\n### 5.2.1. TextBox.SelectAllOnGotKeyboardFocus\nSelects all text in a textbox whgen it gets keyboard focus.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `TextBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:select=\"http://gu.se/Select\"\u003e\n    \u003cGrid select:TextBox.SelectAllOnGotKeyboardFocus=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cTextBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.2.2. TextBox.SelectAllOnClick\nSelects all text in a textbox on click.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `TextBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:select=\"http://gu.se/Select\"\u003e\n    \u003cGrid select:TextBox.SelectAllOnClick=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cTextBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.2.3. TextBox.SelectAllOnDoubleClick\n\nSelects all text in a textbox on doubleclick.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `TextBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:select=\"http://gu.se/Select\"\u003e\n    \u003cGrid select:TextBox.SelectAllOnDoubleClick=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cTextBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n### 5.2.4. TextBox.MoveFocusOnEnter\n\nCaptures enter key and cycles focus to next control.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `TextBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:select=\"http://gu.se/Select\"\u003e\n    \u003cGrid select:TextBox.MoveFocusOnEnter=\"True\"\n          KeyboardNavigation.TabNavigation=\"Cycle\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cTextBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n## 5.3 Gu.Wpf.NumericInput.Touch.TextBox\n### 5.3.1. TextBox.ShowTouchKeyboardOnTouchEnter\nShows onscreen keyboard on touch enter for all controls inheriting from `TextBox`.\nInherits so setting it on a panel or window sets it for all child controls inheriting from `TextBox`.\n\nSample:\n\n```xaml\n\u003cUserControl x:Class=\"Gu.Wpf.NumericInput.Demo.DemoView\"\n             ...\n             xmlns:touch=\"http://gu.se/Touch\"\u003e\n    \u003cGrid touch:TextBox.ShowTouchKeyboardOnTouchEnter=\"True\"\u003e\n        ...\n        \u003cnumeric:DoubleBox .../\u003e\n        \u003cTextBox .../\u003e\n        ...\n    \u003c/Grid\u003e\n```\n\n# 6. Style and Template keys\n- `NumericBox.BaseBoxStyleKey`\n- `NumericBox.SpinnersTemplateKey`\n- `NumericBox.SpinnerPathStyleKey`\n- `NumericBox.SpinnerButtonStyleKey`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguorg%2Fgu.wpf.numericinput","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguorg%2Fgu.wpf.numericinput","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguorg%2Fgu.wpf.numericinput/lists"}