microsoft / microsoft/microsoft-ui-xaml
TextBox.AcceptsReturn and TextBox.Text are setting order sensitive
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
AcceptsReturn and TextBox.Text are setting order sensitive, both in C# and XAML.
Setting `TextBox.Text` with multiple lines of text must be after setting `AcceptsReturn` to `true`. Otherwise, even if `AcceptsReturn` is set to `true`, TextBox only keeps the first line.
For example:
``` xaml
```
When setting `AcceptsReturn` **before** `Text`, it works properly.
``` xaml
```
or
``` C#
TestTextBox.AcceptsReturn = true;
TestTextBox.Text = "line1\rline2";
```
When setting `AcceptsReturn` **after** `Text`, it works improperly.
``` xaml
```
or
``` C#
TestTextBox.Text = "line1\rline2";
TestTextBox.AcceptsReturn = true;
```
### Why is this important?
Especially in XAML, properties should not be considered order sensitive.
Some plugins like XAML Styler will reorder the properties.
When use TextBox in DataTemplate inside ControlTemplate with Style, if the `Text` property is set before the style applied, only the first line will be kept by TextBox, and the text after the first line is lost.
### Steps to reproduce the bug
1. Create a new WinUI 3 project
2. Add a `TextBox` in MainWindow.xaml
3. Try these two code:
``` xaml
```
and
``` xaml
```
### Actual behavior
When the `AcceptsReturn` property is set after `Text`, only the first line is kept by `TextBox`, the rest of text is lost.
### Expected behavior
Setting the `AcceptsReturn` property should not be order sensitive.
### Screenshots
### NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
### Windows version
Windows 11 (24H2): Build 26100
### Additional context
_No response_
Contributor guide
Research direction
Start with the MainWindow.xaml reproduction and the TextBox behavior described in the issue, comparing property-setting order in XAML and C#. Trace the TextBox implementation that processes AcceptsReturn and Text. Done means multiline text is preserved regardless of which property is set first, with coverage for both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100