Skip to main content

Convert Nested Element to Attribute/Attribute to Nested Element


Extracts an attribute from a XAML tag and makes it a child element. You can also perform the reversed operation — inline a child element as an attribute of the parent tag. This refactoring may increase readability if you have too many attributes or a too deep nesting level.


  • Convert Tag to Attribute is available when the caret is on a tag that has a parent tag.
  • Attribute to Nested Element is available when the caret is on an attribute.


  1. Place the caret on an attribute


    The blinking cursor shows the caret’s position at which the Refactoring is available.

    <TextBlock Width="100" Foreground="Blue">
            <Binding Path="Foreground">
                    <RelativeSource Mode="Self" />
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Convert Nested Element to Attribute from the menu (Convert Attribute to Nested Element if you need to extract an attribute).

After execution, the Refactoring inlines the element along with all its child elements as an attribute of the patent tag.

<TextBlock Width="100" Foreground="Blue" Background="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=Self}}">