1

is there an easy and fast way to change between this XAML-Code styles inside Visual Studio XAML-Editor? Perhaps a Key-Shortcut?

Between listed:

<ContentControl Width="130"
                MinWidth="50"
                Height="130"
                MinHeight="50"
                Canvas.Top="150"
                Canvas.Left="470"
                Template="{StaticResource DesignItemTemplate}">

and one line:

    <ContentControl Width="130" MinWidth="50" Height="130" MinHeight="50" Canvas.Top="150" Canvas.Left="470" Template="{StaticResource DesignItemTemplate}">
ASh
  • 34,632
  • 9
  • 60
  • 82
Twister
  • 15
  • 4
  • 1
    Not know of this kind of shortcut. Perhaps you can check [Xaml Formatter](https://stackoverflow.com/questions/46145296/how-to-automatically-format-xaml-code-in-visual-studio). – kennyzx Sep 01 '18 at 05:01
  • This option is available in Visual Studio under options->Text Options->Xaml somewhere and the current code style is called 'smart'. You can change that option and then just format the document. – Silvermind Sep 01 '18 at 07:36

1 Answers1

5

For Visual Studio 2017 go to Tools > Options > Text Editor > XAML > Formatting > Spacing, and select "Insert a single space between attributes". Then you can reformat your xaml file (Ctrl+K+D).

For VSCode you can use XML Formatter. It will make your xaml file to what you need by default.

Ali Doustkani
  • 728
  • 7
  • 14
  • Super, that is what i am looking for. But if i can change between both styles with a short-cut it will be perfect. – Twister Sep 02 '18 at 14:03
  • There is only one way that I know of! And it's a little complicated! All VisualStudio options are stored in the in %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\[VERSION]\Settings\CurrentSettings.vssettings file. This is actually a XML file. What you need to change is placed in ` [HERE]`. Create two Console applications which they set the value to what you need (Preserver, SingleSpace, or NewLine). Then add your applications to VisualStudio (Tools>External Tools). And finally set shortcut keys for them! – Ali Doustkani Sep 02 '18 at 15:06
  • Nice Idea. I tried to change the Attribute with an editor while VS was running. But the attribute does not change. I need to restart VS. – Twister Sep 02 '18 at 18:34
  • Yeah. You're right! Sorry for that!! Check this out: [Writing to the User Settings Store](https://learn.microsoft.com/en-us/visualstudio/extensibility/writing-to-the-user-settings-store?view=vs-2017) – Ali Doustkani Sep 03 '18 at 03:46
  • @Twister sorry to revive an old thread, but did you ever manage to make a keyboard shortcut? I'm currently playing around with it myself – DTynewydd Mar 03 '23 at 16:28