Declare XAML Namespace Reference

Declares a namespace reference for the active qualifier in a XAML document. The member located at the right part of the current expression should exist within the current module. The code provider finds the member namespace and creates a XAML namespace declaration referring to the member namespace.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on a XAML namespace qualifier of an expression, provided that the right part of the expression refers to a member existing within the current module.

Example

Note

The following example implies that "MyControl" and "MyButton" controls are declared in "MyControls" and "AdditionalControls" namespaces appropriately within the current module.

<Window x:Class="MyWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ctrls="clr-namespace:MyControls"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ctrls:MyControl x:Name="myControl1" Content="My control text"/>
        <adctrls:MyButton x:Name="myButton1" Click="MyButtonClicked"/>          
    </Grid>
</Window>

Result

<Window x:Class="MyWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ctrls="clr-namespace:MyControls"
        xmlns:adctrls="clr-namespace:AdditionalControls"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ctrls:MyControl x:Name="myControl1" Content="My control text"/>
        <adctrls:MyButton x:Name="myButton1" Click="MyButtonClicked"/>          
    </Grid>
</Window>

Screenshot

DeclareXamlNamespaceReference