CommunityToolkit / CommunityToolkit/Windows
HeaderedItemsControl margin is doubled
- Dominant language
- C#
- Stars
- 1.1k
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
If you set the `Margin` property on a `HeaderedItemsControl`, the actual margin applied is double the value set.
I suspect this is caused by https://github.com/CommunityToolkit/Windows/blob/b1d8231b5ee810f4e4264be17d9c343ee2785ede/components/HeaderedControls/src/HeaderedItemsControl/HeaderedItemsControl.xaml#L14 because if I create a copy of the style with the margin removed, then the margin is only applied once.
This issue doesn't apply to the `Padding` property though, even though that is set in the template similarly. Padding is not doubled, and removing the padding from the style causes no padding to be applied. I'm not familiar enough with how this works to know why margin and padding are handled differently here, so I don't know if the fix is to simply remove the margin from the style, or if that would cause other issues.
### Steps to reproduce
```text
1. Create a WinUI 3 project with a `HeaderedItemsControl` containing some items. Measure the space around the items.
2. Add `Margin="10"` to the control. Measure the space around the items and observe that it is 20 larger than before instead of 10.
```
### Expected behavior
The amount of margin applied should be the exact value given.
### Screenshots
_No response_
### Code Platform
- [ ] UWP
- [x] WinAppSDK / WinUI 3
- [ ] Web Assembly (WASM)
- [ ] Android
- [ ] iOS
- [ ] MacOS
- [ ] Linux / GTK
### Windows Build Number
- [ ] Windows 10 1809 (Build 17763)
- [ ] Windows 10 1903 (Build 18362)
- [ ] Windows 10 1909 (Build 18363)
- [ ] Windows 10 2004 (Build 19041)
- [ ] Windows 10 20H2 (Build 19042)
- [ ] Windows 10 21H1 (Build 19043)
- [ ] Windows 10 21H2 (Build 19044)
- [ ] Windows 10 22H2 (Build 19045)
- [ ] Windows 11 21H2 (Build 22000)
- [ ] Windows 11 22H2 (Build 22621)
- [ ] Windows 11 23H2 (Build 22631)
- [ ] Windows 11 24H2 (Build 26100)
- [x] Windows 11 25H2 (Build 26200)
- [ ] Windows 11 26H1 (Build 28000)
- [ ] Other (specify)
### Other Windows Build number
_No response_
### App minimum and target SDK version
- [x] Windows 10, version 1809 (Build 17763)
- [ ] Windows 10, version 1903 (Build 18362)
- [ ] Windows 10, version 1909 (Build 18363)
- [ ] Windows 10, version 2004 (Build 19041)
- [ ] Windows 10, version 2104 (Build 20348)
- [ ] Windows 11, version 22H2 (Build 22000)
- [ ] Windows 11, version 24H2 (Build 26100)
- [ ] Windows 11, version 25H2 (Build 26200)
- [ ] Windows 11, version 26H1 (Build 28000)
- [ ] Other (specify)
### Other SDK version
_No response_
### Visual Studio Version
2026
### Visual Studio Build Number
18.4.3
### Device form factor
_No response_
### Additional context
_No response_
### Help us help you
Yes, but only if others can assist.
Contributor guide
Assessment
This issue has not been assessed yet.