Skip to content

Commit d207dd8

Browse files
authored
Generic Number box (#230)
* NumberBox initial port from C++ * Make NumberBox generic * Update build to net8 * Add suppression file for net8 upgrade
1 parent 8511767 commit d207dd8

File tree

110 files changed

+14274
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+14274
-22
lines changed

.github/workflows/CIBuild.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ jobs:
2828
- name: Test WinUIEx
2929
run: |
3030
msbuild /restore /t:Build src\WinUIEx.Tests\WinUIEx.Tests.csproj /p:Platform=x64 /p:Configuration=Release
31-
vstest.console.exe src\WinUIEx.Tests\bin\x64\Release\net6.0-windows10.0.19041.0\WinUIEx.Tests.build.appxrecipe --logger:"console;verbosity=normal" /InIsolation
31+
vstest.console.exe src\WinUIEx.Tests\bin\x64\Release\net8.0-windows10.0.19041.0\WinUIEx.Tests.build.appxrecipe --logger:"console;verbosity=normal" /InIsolation
3232
3333
- name: Test WinUIEx Analyzer
3434
run: |
3535
msbuild /restore /t:Build src\WinUIEx.Analyzers\WinUIEx.Analyzers.Test\WinUIEx.Analyzers.Test.csproj /p:Configuration=Release
36-
vstest.console.exe src\WinUIEx.Analyzers\WinUIEx.Analyzers.Test\bin\Release\net6.0-windows10.0.19041.0\WinUIEx.Analyzers.Test.dll --logger:"console;verbosity=normal" /InIsolation
36+
vstest.console.exe src\WinUIEx.Analyzers\WinUIEx.Analyzers.Test\bin\Release\net8.0-windows10.0.19041.0\WinUIEx.Analyzers.Test.dll --logger:"console;verbosity=normal" /InIsolation
3737
3838
- name: Upload artifacts
3939
uses: actions/upload-artifact@v4

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ Watch WinUIEx covered in the On .NET Live show:
2323
- [Splash Screens](https://dotmorten.github.io/WinUIEx/concepts/Splashscreen.html)
2424
- [OAuth Web Authentication](https://dotmorten.github.io/WinUIEx/concepts/WebAuthenticator.html)
2525
- [Custom Window Backdrops](https://dotmorten.github.io/WinUIEx/concepts/CustomBackdrops.html)
26-
- TitleBar control
26+
- [`NumberBoxInt32`, `NumberBoxDecimal` and `NumberBox<T>`](https://dotmorten.github.io/WinUIEx/concepts/NumberBox.html) - Generic number input controls with support for expressions.
27+
- TitleBar control (Deprecated in favor of WinAppSDK 1.7 TitleBar)
2728
- Code analyzers for Windows App SDK APIs to guide the developer.
2829

29-
3030
And more to come...
3131

3232
### Example of WinUIEx production apps

docs/concepts/NumberBox.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## `NumberBox<T>`
2+
3+
Port of WinUI's NumberBox control to support generic number types.
4+
5+
This control supports validation, increment stepping, and computing inline calculations of basic equations such as multiplication, division, addition, and subtraction.
6+
7+
Port of WinUI's `NumberBox` to `NumberBox<T>` to allow for any numeric datatype. Exposes two controls out of the box: `NumberBoxDecimal` and `NumberBoxInt32` but you can extend with your own by creating the class.
8+
9+
### Binding non-nullable values
10+
The NumberBox<T>.Value is of type `T?` (nullable) to allow for null values when the user clears the text. If you bind to a non-nullable property, you must set `AllowNull="False"` on the control to prevent binding errors.
11+
12+
### Note on assigning decimal values:
13+
To be able to assign Decimal values to the NumberBoxDecimal control, it can't be done in XAML (although x:Bind works). Support for decimal values is a limitation in the Windows App SDK and is supposed to be addressed in v1.8, but is currently not available in 1.8preview1 (see microsoft/WindowsAppSDK#5756)
14+
15+
## Usage
16+
17+
Register the WinUIEx xmlns namespace and add one of the specified controls :
18+
```xml
19+
<ex:NumberBoxInt32 Header="NumberBoxInt32" AllowNull="True"
20+
AcceptsExpression="True"
21+
Value="{x:Bind VM.IntValue, Mode=TwoWay}"
22+
AllowNulls="False"
23+
Minimum="-10"
24+
Maximum="10"
25+
IsWrapEnabled="True"
26+
Description="32bit Integer"
27+
PlaceholderText="Enter a whole number" />
28+
29+
<ex:NumberBoxDecimal Header="NumberBoxDecimal" AllowNull="False"
30+
AcceptsExpression="False"
31+
NumberFormatter="{x:Bind VM.Formatter, Mode=OneWay}"
32+
Value="{x:Bind VM.DecimalValue, Mode=TwoWay}"
33+
Description="Decimal"
34+
PlaceholderText="Enter number" />>
35+
```
36+
to
37+
```xml
38+
<winex:WindowEx xmlns:winex="using:WinUIEx" Width="1024" Height="768" ...>
39+
```
40+
41+
## Extending with your own number-type
42+
43+
First create a custom subclass of `NumberBox<T>`, for example for `float`:
44+
45+
```cs
46+
public class NumberBoxFloat : NumberBox<float>
47+
{
48+
public NumberBoxFloat() => DefaultStyleKey = typeof(NumberBoxFloat);
49+
}
50+
```cs
51+
52+
Next duplicate the control template from the other NumberBox controls and update the target type to match the new type name.
53+

docs/concepts/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
- [Web Authenticator](WebAuthenticator.md)
1010
- [Backdrops](CustomBackdrops.md)
1111

12+
13+
### Controls
14+
- [`NumberBoxInt32`, `NumberBoxDecimal` and `NumberBox<T>`](NumberBox.md)
15+
1216
### Tips and Tricks
1317

1418
- [Using with .NET MAUI](Maui.md)

docs/concepts/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
href: WebAuthenticator.md
1515
- name: Custom Backdrops
1616
href: CustomBackdrops.md
17+
- name: NumberBox
18+
href: NumberBox.md
1719
- name: Object Model Diagram
1820
href: ../api/omd.html
1921
- name: Using with .NET MAUI

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ A set of extension methods and classes to fill some gaps in WinUI 3, mostly arou
1515
- [Splash screen](concepts/Splashscreen.md)
1616
- [OAuth Web Authenticator](concepts/WebAuthenticator.md)
1717
- [Custom Backdrops](concepts/CustomBackdrops.md)
18-
- TitleBar
18+
- [`NumberBoxInt32`, `NumberBoxDecimal` and `NumberBox<T>`](concepts/NumberBox.md)
19+
- TitleBar control (Deprecated in favor of WinAppSDK 1.7 TitleBar)
1920

2021

2122
And more to come...

src/Directory.Build.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
<Authors>Morten Nielsen - https://xaml.dev</Authors>
1818
<Company>Morten Nielsen - https://xaml.dev</Company>
1919
<PackageIcon>logo.png</PackageIcon>
20-
<Version>2.6.0</Version>
21-
<PackageValidationBaselineVersion>2.5.1</PackageValidationBaselineVersion>
20+
<Version>2.7.0</Version>
2221
</PropertyGroup>
2322

2423
<ItemGroup Condition="'$(PackageId)'!=''">
@@ -31,8 +30,8 @@
3130
</PropertyGroup>
3231

3332
<PropertyGroup Label="PackageValidationSettings">
33+
<PackageValidationBaselineVersion>2.6.0</PackageValidationBaselineVersion>
3434
<GenerateCompatibilitySuppressionFile>false</GenerateCompatibilitySuppressionFile>
35-
<CompatibilitySuppressionFilePath Condition="('$(GenerateCompatibilitySuppressionFile)'=='true') OR Exists('$(MSBuildProjectDirectory)\PackageValidationSuppression.txt')">PackageValidationSuppression.txt</CompatibilitySuppressionFilePath>
3635
</PropertyGroup>
3736

3837
<Target Name="SignAssemblies" Condition="Exists($(CertificatePath)) AND '$(CertificatePassword)'!=''" BeforeTargets="CopyFilesToOutputDirectory" DependsOnTargets="ComputeIntermediateSatelliteAssemblies">

src/WinUIEx.Analyzers/WinUIEx.Analyzers.Test/WinUIEx.Analyzers.Test.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
55
<UseWinUI>true</UseWinUI>
66
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
77
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
8+
<RuntimeIdentifiers>win-x64;win-x86;win-arm64</RuntimeIdentifiers>
89
</PropertyGroup>
910

1011
<ItemGroup>

src/WinUIEx.Tests/WinUIEx.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
4-
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
55
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
66
<RootNamespace>WinUIUnitTests</RootNamespace>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<Platforms>x86;x64;arm64</Platforms>
9-
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
9+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
1010
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
1111
<UseWinUI>true</UseWinUI>
1212
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
3+
<Suppressions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<Suppression>
5+
<DiagnosticId>PKV006</DiagnosticId>
6+
<Target>net6.0-windows10.0.19041</Target>
7+
</Suppression>
8+
</Suppressions>

0 commit comments

Comments
 (0)