dotnet / dotnet/maui

Binding an Item's height and width to another item's height and Width in XAML causes exceptions and unexpected behaviors

Open
#6,200 6 comments 0 reactions 0 assignees View on GitHub
area-layout platform/android s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 14h
Merged PRs (30d)
296

Description

### Description

Every time I try binding a view's height or width to another view's height or width in XAML,
I get an exception, stating `System.InvalidOperationException: 'Width cannot be less than zero.'`
After getting this exception, I did a value converter to make the value I bind to be always greater than 0, but The value of the referenced view's sizes always keeps increasing forever.

### Steps to Reproduce

I reproduced both bugs in two pages I set here in this repository. https://github.com/DamienDoumer/MAUIBugs/tree/master/MAUIBugs/ViewSizeReferenceBug

### Version with bug

Release Candidate 1 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Android

### Affected platform versions

All

### Did you find any workaround?

_No response_

### Relevant log output

```shell
**System.InvalidOperationException:** 'Width cannot be less than zero.'
```

Contributor guide

Open the contributing guide

Research direction

Start with the two-page reproduction in the MAUIBugs/ViewSizeReferenceBug repository and run it on Android. Trace the height and width bindings that produce the negative-width exception and repeated size increase; done means both behaviors no longer occur in the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, xml
Domain
frontend, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.