microsoft-ui-xaml: Can't set the border properties of the NumberBox.
Describe the bug
Border properties like BorderBrush or BorderThickness can’t change from xaml.
Steps to reproduce the bug
Steps to reproduce the behavior:
<ComboBox Header="ComboxBorder" BorderThickness="0.5" BorderBrush="DarkGray" />
<controls:NumberBox Header="ComboxBorder" BorderThickness="0.5" BorderBrush="DarkGray"/>
Expected behavior
Border properties should work like other controls (ComboBox, TextBox,…)
Screenshots

Version Info
NuGet package version:
| Windows 10 version | Saw the problem? |
|---|---|
| Insider Build (xxxxx) | |
| November 2019 Update (18363) | Yes |
| May 2019 Update (18362) | |
| October 2018 Update (17763) | |
| April 2018 Update (17134) | |
| Fall Creators Update (16299) | |
| Creators Update (15063) |
| Device form factor | Saw the problem? |
|---|---|
| Desktop | Yes |
| Mobile | |
| Xbox | |
| Surface Hub | |
| IoT |
Additional context
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 18 (13 by maintainers)
To clarify: In SpinButtonPlacementMode.Inline, if we apply properties like BorderThickness and BorderBrush, is the desired look the following?
In that case, I would like to tackle this one.
@SavoySchuler I have finalized my API proposal now (including a test implementation in a local branch of mine).
To recap, the NumberBox uses three borders to achieve its visual look in all the different visual states: A border around its input field (the TextBox and its border) and around each of its SpinButtons when in SpinButtonPlacementMode::Inline. See the following image of a NumberBox in rest mode:
To achieve the uniform border thickness used here, the border thickness values of the spin buttons are of the form
0,X,X,X(so the border’s left side thickness is set to 0).Currently, setting the
NumberBox.BorderBrushAPI has no effect on the NumberBox which @hipo760 lists in their opening post. If one wishes to easily customize the border thickness of aNumberBox, lightweight styling has to be used instead for now. To add support for theNumberBox.BorderThicknessAPI and make it work as intended, we need to filter the template bound BorderThickness for the spin buttons accordingly. In other words, we need to set theThickness.Leftfield of a givenThicknessvalue to 0 (zero). See the following GIF which shows what will happen to the NumberBox’s border if we template bind to theNumberBox.BorderThicknesswithout filtering the thickness value as described above:As a comparison, here is how the
NumberBox.BorderThicknessAPI will be applied with correct filtering of the template bound BorderThickness:To achieve this, I propose adding a new API similar to the existing CornerRadiusFilterConverter API. This new API will be used to create a new
Thicknessstruct from an existing one, while using a configurable mask to set some of theThicknessfields to 0 while keeping the rest. See below for an API proposal and an API example.API proposal
API Notes
ThicknessMaskConverterspecifying which values of aThicknessstruct will be set to 0 (zero) and which to keep. Can be a combination of multipleThicknessMaskKindsmembers.Maskdependency property.Thicknessto a newThicknessby setting some fields to 0 specified byMaskand leave the rest intact.API Example
Consuming the proposed API is similar to how you would use the
CornerRadiusFilterConverterAPI. See, for example, the following XAML below. Here, we first create a new instance of theThicknessMaskConverterclass with our desiredMaskand then use our converter in a binding. For demo purposes, I created an exampleThicknessresource called ExampleThickness in order to use a binding. In the NumberBox ControlTemplate case, we would instead work with a commonly used TemplatedParent relative binding.The XAML above gives us the following TextBox look:
As already mentioned above we would use the
ThicknessMaskConverterAPI in the NumberBox ControlTemplate like this:where LeftThicknessMaskConverter is defined as:
Additional Notes
First and foremost, I’d like to give a shoutout to @stevenbrix who is always a great help when I have specific implementation questions. Thank you, Steve!
Secondly, while we can view this API as filtering out specific
Thicknessfields and throwing away others (by setting them to 0) I went with the “Mask” terminology for now. The reason being that I can imagine we might be more interested interested in ignoring the value of only 1-2 fields of aThicknessinstead of 3-4 fields. Take our NumberBox case here, for example. We filter out the Top, Right and Bottom values of aThicknessvalue and ignore only theLeftvalue. If I would have gone with the filter terminology, here’s how my XAML would have looked like instead:Compare that to the XAML using the
Maskterminology:Obviously, I am open to renaming and restructuring the proposed API if the team prefers the name ThicknessFilterConverter (or any other name) over my proposed naming.
Summary
The proposed
ThicknessMaskConverterAPI will be a great helper API to achieve properNumberBox.BorderThicknesssupport. More broadly speaking it is to be used in a (Template) Binding to create a newThicknessstruct from an existing one, setting only some of the fields to 0 while keeping the rest.