XamlStyler icon indicating copy to clipboard operation
XamlStyler copied to clipboard

Option for controlling number of newlines around elements

Open danielchalmers opened this issue 6 years ago • 7 comments

Proposal: Two new options for controlling newlines between and around elements.

  1. An enum of where to put the newlines: Between, Surround, None, and Ignore (default)
  2. An integer for choosing the number of newlines

With Between and newlines 1, this:

<!-- based on `Local child control style` from wpf-tutorial.com/styles/using-styles -->
<Window x:Class="WpfTutorialSamples.Styles.SimpleStyleSample">

    <StackPanel Margin="10">
        <StackPanel.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Foreground" Value="Gray" />
                <Setter Property="FontSize" Value="24" />
            </Style>
        </StackPanel.Resources>
        <TextBlock>Header 1</TextBlock>



        <TextBlock>Header 2</TextBlock>
        <TextBlock Foreground="Blue">Header 3</TextBlock>
    </StackPanel>
</Window>

becomes:

<!-- based on `Local child control style` from wpf-tutorial.com/styles/using-styles -->
<Window x:Class="WpfTutorialSamples.Styles.SimpleStyleSample">
    <StackPanel Margin="10">
        <StackPanel.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Foreground" Value="Gray" />

                <Setter Property="FontSize" Value="24" />
            </Style>
        </StackPanel.Resources>

        <TextBlock>Header 1</TextBlock>

        <TextBlock>Header 2</TextBlock>

        <TextBlock Foreground="Blue">Header 3</TextBlock>
    </StackPanel>
</Window>

Surround and newlines 1:

<!-- based on `Local child control style` from wpf-tutorial.com/styles/using-styles -->
<Window x:Class="WpfTutorialSamples.Styles.SimpleStyleSample">

    <StackPanel Margin="10">

        <StackPanel.Resources>

            <Style TargetType="TextBlock">

                <Setter Property="Foreground" Value="Gray" />

                <Setter Property="FontSize" Value="24" />

            </Style>

        </StackPanel.Resources>

        <TextBlock>Header 1</TextBlock>

        <TextBlock>Header 2</TextBlock>

        <TextBlock Foreground="Blue">Header 3</TextBlock>

    </StackPanel>

</Window>

None:

<!-- based on `Local child control style` from wpf-tutorial.com/styles/using-styles -->
<Window x:Class="WpfTutorialSamples.Styles.SimpleStyleSample">
    <StackPanel Margin="10">
        <StackPanel.Resources>
            <Style TargetType="TextBlock">
                <Setter Property="Foreground" Value="Gray" />
                <Setter Property="FontSize" Value="24" />
            </Style>
        </StackPanel.Resources>
        <TextBlock>Header 1</TextBlock>
        <TextBlock>Header 2</TextBlock>
        <TextBlock Foreground="Blue">Header 3</TextBlock>
    </StackPanel>
</Window>

Visual Studio has Element Spacing that can preserve, collapse, or remove newlines, but AFAIK no way of adding them. image

danielchalmers avatar Mar 08 '18 23:03 danielchalmers

Thanks for the suggestion! Do you imagine this applying across the board or only the children of certain elements? For example, how would Setters in Style definitions or VisualStates be formatted?

grochocki avatar Mar 09 '18 00:03 grochocki

@grochocki Hi! I imagine this being applied on all elements, maybe with an option for exclusions if needed? I've updated the proposal with better examples and a new option to control if newlines should be surrounding elements, or between them.

danielchalmers avatar Mar 09 '18 01:03 danielchalmers

Great, thanks for adding those details and examples!

grochocki avatar Mar 12 '18 22:03 grochocki

Hi, Any news about this issue? I would have a similar request :)

I usually put newlines to organize logical blocks, such as elements with same Grid.Column/Row, or forms, etc. I would like to delete extra newlines and only keep a minimum (default would be 1 line minimum for example).

<StackPanel Margin="10">
     <TextBlock>Header 1</TextBlock>
     <TextBlock>Header 2</TextBlock>



     <TextBlock Foreground="Blue">Header 3</TextBlock>
 </StackPanel>

would become

<StackPanel Margin="10">
     <TextBlock>Header 1</TextBlock>
     <TextBlock>Header 2</TextBlock>

     <TextBlock Foreground="Blue">Header 3</TextBlock>
</StackPanel>

What do you think?

cyrilcathala avatar May 29 '19 16:05 cyrilcathala

Related to #170

grochocki avatar Jun 23 '19 22:06 grochocki

This may build on or supersede #170, but we believe this one might be trickier to implement, especially the between option. We would like to better understand how this option works before adding it to the project, but are otherwise supportive of this improvement.

grochocki avatar Apr 09 '20 06:04 grochocki

BOOM! This was the first feature I looked for.

Has there been any movement on this? I'd love to help but currently I'm so stacked I've no time to dig in.

jamsoft avatar Jan 23 '21 09:01 jamsoft