microsoft / microsoft/microsoft-ui-xaml

Can't set decimal values in XAML

Open
#10,776 7 comments 8 reactions 0 assignees View on GitHub
area-XamlCompiler bug team-Markup
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

With 1.8 support for Decimals was added to the runtime types. I fully expected to now be able to set Decimal values on dependency properties. However this seem to not work still.

### Why is this important?

For users who need to handle decimal values like a [Decimal version of the NumberBox](https://dotmorten.github.io/WinUIEx/concepts/NumberBox.html), where you currently can't set the min/max values in xaml, but have to resort to code-behind or using x:bind.

### Steps to reproduce the bug

1. Add the following control:
```cs
public class MyControl : Control
{
public decimal DecimalValue
{
get { return (decimal)GetValue(MyDecimalProperty); }
set { SetValue(MyDecimalProperty, value); }
}

public static readonly DependencyProperty MyDecimalProperty =
DependencyProperty.Register(nameof(DecimalValue), typeof(decimal),
typeof(MyControl), new PropertyMetadata(0m));
}
```
2. Reference it in XAML and set the DecimalValue property:
```xml

```
3. Compile and observe error:
`1>C:\DecimalTest\DecimalTest\MainWindow.xaml(14,26): XamlCompiler error WMC0055: Cannot assign text value '10' into property 'DecimalValue' of type 'Decimal'`

### Actual behavior

Compile error

### Expected behavior

Able to assign Decimal in XAML (note: x:Bind to decimal values does work)

### Screenshots

Image

### NuGet package version

WinUI 3 - Windows App SDK 1.8.0: 1.8.250907003

### Windows version

Windows 11 (24H2): Build 26100

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the MyControl dependency property and the XAML value DecimalValue="10" using Windows App SDK 1.8. Compare this failure with the reported working x:Bind case, then trace the XAML compilation path responsible for converting text to Decimal. Done means the sample compiles and assigns decimal values in XAML without regressing existing bindings.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.