This is a WPF numeric up-down counter. I wrote it because WPF framework doesn't embed this useful component, and I need it in other projects
This component intends to only hold a numeric value, whereas the TextBox aims to hold any string
- Installation
- How to use
- Exposed properties
- Exposed events
- Documentation
- Dependencies
- Tests
- Changelog
- License
- Credits
- Download the latest release from the Releases section
- In your project, add a reference to the DLL file you just downloaded by browsing it
- In your markup,
- import the namespace by adding the following to your component declaration (where you can see the
xlmns
declarations):xmlns:vc="clr-namespace:WPFUpDownControl;assembly=WPFUpDownControl"
- add the control with the following:
<vc:UpDownControl/>
- then set the properties
- import the namespace by adding the following to your component declaration (where you can see the
Note
This section applies to the final user
The only way to change the value is, for now, by clicking the buttons. Additional ways will be added in upcoming versions
These are the properties you'll use in your markup
Note
These properties are of decimal
type. It's up to you to cast to other types if needed
Here's a snippet example showing how to set these properties in your markup:
<vc:UpDownControl CurrentValue="5.1" Step="0.75" MinValue="1"/>
Here's the same one seen from your code-behind (assuming you named the variable as "WUDC"):
WUDC.CurrentValue=5.1m;
WUDC.Step=0.75m;
WUDC.MinValue=1m;
This is the counter's value
Note
This value is required
Warning
Be careful when changing this one in your code-behind. If MinValue
and/or MaxValue
are defined, it always has to be between these two ones (i.e. MinValue (if defined) <= CurrentValue <= MaxValue (if defined)
). Otherwise, an exception will pop up
For example, let's say you have the following:
CurrentValue=1.5
MaxValue=2
MinValue=-3
.
Setting CurrentValue
to 3
will throw an exception. Whereas setting MaxValue
to 3.1
, then CurrentValue
to 3
won't
This is the value which is added/subtracted when you increase/decrease the current one
Note
This value is required
Note
It must be defined and positive (i.e. >= 0
)
This is the value the current one can't go under
Note
This value is optional
Note
It must be less than current value and (if defined) maximum one, i.e. MinValue (if defined) <= CurrentValue
and MinValue (if defined) <= MaxValue (if defined)
These are the events you may subscribe to
Here's the expanded previous snippet example showing how to subscribe to these events in your markup:
<vc:UpDownControl CurrentValue="5.1" Step="0.75" MinValue="1" CurrentValueChanged="WUDC_CurrentValueChanged" StepChanged="WUDC_StepChanged" MinValueChanged="WUDC_MinValueChanged"/>
Here's the same one seen from your code-behind (still assuming you named the variable as "WUDC"):
WUDC.CurrentValue=5.1m;
WUDC.Step=0.75m;
WUDC.MinValue=1m;
WUDC.CurrentValueChanged+=WUDC_CurrentValueChanged;
WUDC.StepChanged+=WUDC_StepChanged;
WUDC.MinValueChanged+=WUDC_MinValueChanged;
This event is triggered when the current value changes
This event is triggered when the step changes
This event is triggered when the minimum value changes
The code documentation is written in XML (as it's the C# standard way)
- .NET framework 4.8.1+. This project intends to run on Windows
Tests are functional ones and performed manually. They include the following:
- checking required properties are set and not null
- checking you can subscribe to and unsubscribe from events
- checking buttons change the current value according to the step
- checking current value remains within defined minimum and/or maximum value(s)
- checking minimum value is always less than maximum and current ones
See the changelog
This project is licensed under the Apache 2.0 license
I did a 1st try for the XAML markup, but didn't get the result I wanted. So I picked part of the markup from Stopbyte/WPF-Numeric-Spinner-NumericUpDown project instead
As I found the events system quite uneasy to understand at first (it's the 1st time I'm diving into this), I asked ChatGPT to write the CurrentValueChanged
event (including the dependency property). Then I copied/pasted/adapted in order to make the following ones