XAML SG could warn when binding to a readonly property
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
For example:
```xml
```
Is a valid XAML, but at runtime the height is not applied, and it produces a warning log message:
```
Microsoft.Maui.Controls.BindableObject: Warning: Cannot set the BindableProperty "Height" because it is readonly.
```
Unfortunately, the message is not very actionable as it doesn't say on which element the property is being set and/or where it's set from. It' possible to diagnose this by plugging in a custom logger and setting a breakpoint into it, but that's pretty tedious.
Also - it's pretty easy to miss this log message completely and not know that the value is not applied.
With XAML SG, we generate the call to `SetValue` at compile time, so in theory we might be able to detect read-only properties and produce a warning at compile time.
### Public API Changes
N/A
### Intended Use-Case
Detect XAML which will not do what it "seemingly" does.
Ran into this with AI generated XAML. IntelliSense seems to know about it, and it doesn't offer `Height` as a property to be used in XAML, but it's still easy to get this wrong.
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by locating the XAML source-generator code that emits SetValue for bindings, then inspect how readonly BindableProperty values are represented. Done means the sample produces a compile-time warning that identifies the affected element and property.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- mobile-dev, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100