Ticket T566780
Visible to All Users

XAML Styling inconsistent/surprising and cannot be configured

created 7 years ago

I've gotten to do more XAML lately and wanted to get rid of XamlStyler (which was more of a legacy thing from a time when CRR didn't have XAML formatting), but I noticed some inconsistencies and things that I couldn't really change (or didn't work as I expected them).

One thing that is kind of neat, but at the same time inconsistent (or surprising if you like) is the fact that CRR seems to insert empty lines at the first child level:

XAML
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="525" Height="350"> <Window.Resources> <DataTemplate DataType="String" /> </Window.Resources> <Grid> <StackPanel> <StackPanel.Resources> <DataTemplate DataType="String" /> </StackPanel.Resources> <TextBlock /> <TextBlock /> <TextBlock /> </StackPanel> <Label /> <Label /> <Label /> </Grid> </Window>

The empty lines before/after Window.Resources and Grid were added by CRR, but they do not apply to levels deeper down (I would've expected the same thing to happen for StackPanel.Resources for example). And at the same time, I cannot tell CRR to not do it.
So, the least I'd like to see here is a switch to enable/disable this behavior (because I do like it in general, but I'd find it hard to define a rule set of where I'd want them or not; for example it would be nice to have an empty line between Grid.Row entries but not between members of the same Grid.Row but different Grid.Column; only have it between elements and not at the beginning/end; etc.)

The other thing is that CRR doesn't seem to properly sort attached property attributes in a custom namespace, even though my configuration appears to be correct-ish.
TBF I just copy-pasted my old settings from XamlStyler, and it includes two rules that might match (one is star-colon-star *:* which should sort all custom namespace attributes first; followed by star * to sort all non-namespace attributes afterwards):

XAML
<Label Grid.Row="2" Grid.Column="1" local:Test.PropertyB="2" Content="Text" local:Test.PropertyA="1"/>

But instead, the namespace attributes are left as-is without any sorting. In fact, all attributes are left as-is as soon as namespace attributes are present; no sorting happens there.

Answers approved by DevExpress Support

created 7 years ago

Hi Emmanuel,
If you want to avoid adding empty lines between root child elements, please change a value of the 'Empty Line Count Between Root Children' option to 0:
https://www.screencast.com/t/bepPaFKl
To help us reproduce the second issue, please send us the current value of the 'Attribute order' option.

    Comments (2)
    EW EW
    Emanuel Wlaschitz 7 years ago

      Oh neat, I didn't notice the Advanced tab over there, thanks!

      For Attribute order, I have the following:

      C#
      x:Class xmlns, xmlns:x xmlns:* x:Key, Key, x:Name, Name, x:Uid, Uid, Title Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight Margin, Padding, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment, Panel.ZIndex *:*, * PageSource, PageIndex, Offset, Color, TargetName, Property, Value, StartPoint, EndPoint mc:Ignorable, d:IsDataSource, d:LayoutOverrides, d:IsStaticText Storyboard.*, From, To, Duration

      That is a 1:1 copy from XamlStyler (which looked similar, so I just copied them over without changing anything).
      I can reproduce that in a newly created WPF project that has a simple Test class with two attached properties added (simple expansion of the Visual Studio Snippet propa with names that make the ordering obvious).

      Let me know if you need anything else here.

      AE AE
      Alex Eg (DevExpress) 7 years ago

        Emanuel,
        I've created a separate ticket on your behalf (XAML Formatting - Attributes aren't sorted correctly when using attached properties). It has been placed in our processing queue and will be answered shortly.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.