Skip to main content

Undeclared static resource

In This Article

CodeRush Classic displays the Undeclared static resource code issue if the current XAML static resource is not declared.

#Fix

Declare the static resource.

#Purpose

Highlights the reference to an undeclared static resource, which causes the XAML parse exception.

#Example

<Window x:Class="MyApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyApplication"
        Title="MainWindow" Height="500" Width="400">
    <Grid>
        <local:MyControl 
            MyClassProperty = "{StaticResource MyClass}"
        />
    </Grid>
</Window>

Fix:

<Window x:Class="MyApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyApplication"
        Title="MainWindow" Height="500" Width="400">
    <Grid>
        <Grid.Resources>
            <local:MyClass x:Key="MyClass"/>
        </Grid.Resources>
        <local:MyControl 
            MyClassProperty = "{StaticResource MyClass}"
        />
    </Grid>
</Window>