You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: XAML formatting inserts a line break between adjacent inline elements and changes the rendered text #1912
First of all, thank you very much for creating CSharpier!
I love it because it ends all styling/formatting wars, so it stops teams wasting value time on this topic which is better spend on other things.
When two inline elements (e.g. in a TextBlock) follow each other directly, without any whitespace between them, CSharpier puts each of them on its own line. In XAML this is not a pure formatting change. The inserted line break is rendered as a space, so
the text shown on screen changes.
The problem occurs with xmlWhitespaceSensitivity set to ignore and also with it set to strict. There is currently no setting that avoids it.
This affects both WPF (.xaml) and Avalonia (.axaml) files in my project.
Steps to Reproduce
Use the following configuration in .csharpierrc.json:
The rendered text is now Sub total instead of Subtotal, so the formatting changed the visible output of the application.
The reason is that TextBlock.Inlines is an InlineCollection. That class is marked with WhitespaceSignificantCollectionAttribute, which tells the XAML parser to treat whitespace inside the collection as significant. A line break between two inline elements is normalized into a single space and is really
rendered. See "White-space processing in XAML", section "White space and text content models in WPF": https://learn.microsoft.com/en-us/dotnet/desktop/xaml-services/white-space-processing
So for elements inside such a collection the following rule has to hold, independent of the xmlWhitespaceSensitivity setting: if there was no whitespace between two elements in the source, none may be inserted.
I expect the same problem for other inline elements in the same position, for example Bold, Italic, Span and Hyperlink, and for mixed content like <TextBlock>Sub<Run>total</Run></TextBlock>.
As a workaround, a <!-- csharpier-ignore --> comment before the affected element keeps the formatting intact. That works, but it is not practical when many views contain such text, and it is easy to forget when writing new XAML.
Another workaround (with the same issue of having to remember to use it) is adding xml:space="preserve" to an element, but it currently has the same problem that it will split the child elements. It also looks like I haven't documented that csharpier (mostly) honors it.
I think the best fix is to not add new lines between elements that don't currently have any whitespace regardless of their parent. That will work for the built in xaml types as well as any custom or 3rd party types.
I think the best fix is to not add new lines between elements that don't currently have any whitespace regardless of their parent.
That sounds very reasonable to me!
Although to be honest I haven't thought through the implications and unwanted side effects this policy might have and whether it would cover all scenarios.
I guess this is a good candidate to let claude code or codex think through.
Hi @belav, thank you so much for fixing this so quickly! 🙏
I'm trying to move a few of my open-source WPF and Avalonia projects from XamlStyler to CSharpier, and this is the one thing holding me back.
I built 1.3.0 with #1915 cherry-picked on top and gave it a fairly thorough XAML workout. With the fix it works great!
If it's not too much trouble, would you consider publishing a 1.4.0 prerelease (or a patch release) that includes it? That would let me switch over without maintaining a private build of CSharpier and CSharpier.MsBuild in each repo. No pressure at all, of course. I completely understand if you'd rather wait until 1.4.0 is ready.
Thanks again for CSharpier. It's been a real pleasure to use. ❤️
Activity
belav commentedon Sep 2, 2026
Another workaround (with the same issue of having to remember to use it) is adding
xml:space="preserve"to an element, but it currently has the same problem that it will split the child elements. It also looks like I haven't documented that csharpier (mostly) honors it.I think the best fix is to not add new lines between elements that don't currently have any whitespace regardless of their parent. That will work for the built in xaml types as well as any custom or 3rd party types.
rent-a-developer commentedon Sep 4, 2026
Thank you @belav for your quick reply!
That sounds very reasonable to me!
Although to be honest I haven't thought through the implications and unwanted side effects this policy might have and whether it would cover all scenarios.
I guess this is a good candidate to let claude code or codex think through.
Don't insert new lines between elements if they don't have any whites…
Don't insert new lines between elements if they don't have any whites…
Don't insert new lines between elements if they don't have any whites… (
rent-a-developer commentedon Sep 13, 2026
@belav
Nice work! Thank you a lot!
Do you have any idea for a release date yet?
rent-a-developer commentedon Oct 20, 2026
Hi @belav, thank you so much for fixing this so quickly! 🙏
I'm trying to move a few of my open-source WPF and Avalonia projects from XamlStyler to CSharpier, and this is the one thing holding me back.
I built 1.3.0 with #1915 cherry-picked on top and gave it a fairly thorough XAML workout. With the fix it works great!
If it's not too much trouble, would you consider publishing a 1.4.0 prerelease (or a patch release) that includes it? That would let me switch over without maintaining a private build of CSharpier and CSharpier.MsBuild in each repo. No pressure at all, of course. I completely understand if you'd rather wait until 1.4.0 is ready.
Thanks again for CSharpier. It's been a real pleasure to use. ❤️