Extract to XAML Resource (XAML)
In This Article
Extracts the string at the caret into an XAML resource file, and inserts the reference to the appropriate word in this resource file. The refactoring offers to create a new resource file or choose an existing one if any.
#Availability
Available from the context menu or via shortcuts:
- when the caret is on an attribute value.
#Notes
There is also a Extract to XAML Resource (replace all) variant of this refactoring, which removes all string values in a file that match the string at the caret.
#Examples
<!--Window XAML file-->
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Button
Content="Click me"
Height="25"
Width="80"
ToolTip="Tool tip text"/>
<CheckBox
Content="Check me"
Height="25"
Width="100"
Margin="202,174,201,112"
ToolTip="Tool tip text"/>
</Grid>
</Window>
Result:
<!--Window XAML file-->
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Words1.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Button
Content="Click me"
Height="25"
Width="80"
ToolTip="{StaticResource Word_Tooltiptext}"/>
<CheckBox
Content="Check me"
Height="25"
Width="100"
Margin="202,174,201,112"
ToolTip="{StaticResource Word_Tooltiptext}"/>
</Grid>
</Window>