FrameworkElement.TryFindResource Method
Searches for a resource with the specified key, and returns that resource if found.
Namespace: System.Windows
Assembly: PresentationFramework (in PresentationFramework.dll)
Parameters
- resourceKey
- Type: System.Object
The key identifier of the resource to be found.
Return Value
Type: System.ObjectThe found resource, or null if no resource with the provided key is found.
If the resource is not found on the calling element, the parent resource tree is searched upward through the logical tree, in the same way that the tree would be searched if a resource were requested by key at run time. The method returns null only if no resource of that key existed anywhere in the resource tree, per the existing conditions of the tree at the time that TryFindResource is called.
Typically you would immediately cast the return value to the type of the property that you were attempting to set with the returned resource value.
The FindResource method has similar behavior, except that it throws an exception if no resource with the provided key was returned.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.