Application.FindResource Method

Searches for a user interface (UI) resource, such as a Style or Brush, with the specified key, and raises an exception if the requested resource is not found (see Resources Overview).

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)

public Object FindResource (
	Object resourceKey
public Object FindResource (
	Object resourceKey
public function FindResource (
	resourceKey : Object
) : Object
You cannot use methods in XAML.



The name of the resource to find.

Return Value

The requested resource object. If the requested resource is not found, ResourceReferenceKeyNotFoundException is raised.

Exception typeCondition


The resource cannot be found.

FindResource will first look in application-scope resources for the specified resource. Application-scope resources are managed by Application, and are exposed from the Resources property. If the specified resource is not found in the set of application-scope resources, FindResource then next searches the system resources. System resources are shell resources defined by the user, and include colors, fonts, and shell configurations. These are exposed from the SystemColors, SystemFonts, and SystemParameters types, respectively, as static properties. To use FindResource to acquire them, these types also expose resource key properties that are designed to be passed to FindResource eg IconWidthKey.

Because FindResource returns an object, you must cast the returned value to the appropriate type if the resource is found.


If you call this method for a key that cannot be found, an exception is raised. If you do not want to handle exceptions that result from calling FindResource, call TryFindResource instead; TryFindResource returns a a null reference (Nothing in Visual Basic) reference when a requested resource cannot be found, and does not raise an exception.

This method is thread-safe, and can be called from any thread.

The following example shows how to use FindResource to find a resource, and to handle ResourceReferenceKeyNotFoundException if the resource is not found.

void findResourceButton_Click(object sender, RoutedEventArgs e) {
  try {
    object resource = Application.Current.FindResource("UnfindableResource");
  catch (ResourceReferenceKeyNotFoundException ex) {
    MessageBox.Show("Resource not found.");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0