Recently one of my colleagues started using spaces instead of commas as separators for specific values in Thickness fields like Margin and Padding:
<Label Margin="0 1 2 3"/>
While previously we used commas:
<Label Margin="0,1,2,3"/>
He says he saw a lot of usage of this style in XAML examples across the web, but could not provide any of them quickly. His code is working in .NET 6 project with WPF, but we have another projects with different .NET targets so I started digging if this style is acceptable is general.
Some parts of WPF documentation restrict usage to commas only:
The four values must be separated with commas; spaces are not allowed.
General article about Thickness in WPF does not mention separators at all (as for .NET Framework 4.8 and above), but provides an example with a starting whitespace, so I assume it is is OK:
<object property=" left,top,right,bottom" ... />
Xamarin docs includes an example with both commas and spaces:
<Label Text="Xamarin.Android" Margin="0, 20, 15, 5" />
Although similar article for MAUI suggests an example without spaces and does not mention them:
<Label Text=".NET Android" Margin="0,20,15,5" />
Finally UWP docs explicitely says that commas and spaces are allowed to use, and one user even created an issue for WinUI3 when caught a problem with spaces.
So,
I have created all the differents project you mentioned. I found that:
,
to separate the values. If you use the space, it will throw the error (can't convert value "1 1 1 1"
to Thickness).,
and space to separate the values.In addition, if you both have ,
and space in the values, the space seems will be ignored. So I suggest you use the ,
to do that. Because the constructor of the Thickness class also used the ,
. Such as new Thickness(left,top,right,bottom)
;