Tutorial :Insufferable word wrap in Visual Studio XAML editor - is there any relief for 2010?



Question:

Just curious if the XAML editor is any better at auto-formatting and wrapping attributes in Visual Studio 2010.

Here's how the editor auto wraps attributes in VS 2008:

<StackPanel Grid.Row="0" Grid.ColumnSpan="3">      <StackPanel Orientation="Horizontal">          <TextBlock VerticalAlignment="Center" FontWeight="Bold"  Text="Current User:" />          <ComboBox x:Name="_usersComboBox" Margin="5,0,0,0" Width="200"  ItemsSource="{Binding Users}" SelectedValuePath="Name"  SelectedValue="System Administration">              <ComboBox.ItemTemplate>                  <DataTemplate>  

Here's how I'd like the editor to auto wrap attributes:

<StackPanel Grid.Row="0" Grid.ColumnSpan="3">      <StackPanel Orientation="Horizontal">          <TextBlock VerticalAlignment="Center" FontWeight="Bold"              Text="Current User:" />          <ComboBox x:Name="_usersComboBox" Margin="5,0,0,0" Width="200"              ItemsSource="{Binding Users}" SelectedValuePath="Name"              SelectedValue="System Administration">              <ComboBox.ItemTemplate>                  <DataTemplate>  

Does VS 2010 grant my wish?


Solution:1

Nope. You should open up a Connect for that:

https://connect.microsoft.com/VisualStudio/feedback/CreateFeedbackForm.aspx?FeedbackFormConfigurationID=3783&FeedbackType=2

May not make it until SP1, but I've found them pretty responsive to suggestions during the B2 cycle. You might be surprised....


Solution:2

There's something close to that.

The new editor in VS2010 supports an auto-indent word wrap mode. There is no way to activate it within the product, but a PM on our team wrote a quick extension that enables that mode. You can download it from the VS Gallery, or download it from the extension manager in VS2010 by searching for it by name ("word wrap" should be enough) or searching for Brittany Behrens, who wrote the extension.


Solution:3

I've only just found this question, after having already put up a request on the VS 2010 suggestions forum.

This video (the first 20 secs should do it) shows XAML being reformatted continuously whilst it's edited with no user intervention - the XAML simply 'reflows' during typing, drag'n drop etc.

My suggestion goes a bit further because I propose fully automated 'virtual formatting', using margins instead of tabs/spaces, this means word-wrap will always work just like in a word processor. A sample screenshot shows this - leading whitespace characters (with a yellow background) are only present within an xml:space preserve block:

enter image description here

Word-wrap and formatting is quite complex - there are a few things going on in the screenshot:

  1. The RTF includes hanging-indent formatting for element or attribute content, so wrapped text will have extra indentation - to make it clear that it's wrapped (see the wrapped entation value and margin and width attributes)

  2. All attributes are aligned under one another

  3. If an attribute value has line-feeds, new lines will be aligned with the first line.

  4. Required whitespace in preformatted text is preserved whilst still keeping indentation intact.

  5. [Important] All formatting is done at the same time as syntax-coloring, based on the position of line-feeds in the XAML context. Word-wrap just works like a word-processor because of the indent data carried within the line-feeds.

If this can't be done for Visual Studio, then perhaps we could see this first in Kaxaml?.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »