Application.TryFindResource Method
Searches for the specified resource.
Assembly: PresentationFramework (in PresentationFramework.dll)
Parameters
- resourceKey
- Type: System.Object
The name of the resource to find.
Return Value
Type: System.ObjectThe requested resource object. If the requested resource is not found, a null reference is returned.
TryFindResource 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, TryFindResource 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 TryFindResource to acquire them, these types also expose resource key properties that are designed to be passed to TryFindResource; for example, IconWidthKey.
Because TryFindResource returns an object, you must cast the returned value to the appropriate type if the resource is found.
This method is thread safe and can be called from any thread.
The following example shows how to use TryFindResource to acquire a resource.
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml" > <Application.Resources> <Image x:Key="ApplicationResource" Source="ApplicationResource.bmp" /> </Application.Resources> </Application>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
