Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

TryFindResource returning non-null value on unfound resource

01 Sep 2013, 21:11

I am trying to gracefully handle loading resources which may not exist within my xaml files.

According to the documentation:
If a resource was requested by a FindResource call, and was not found, an exception is raised.
This is happening correctly. I don't want exceptions thrown though so I am using TryFindResource. According to the documentation:
If a resource was requested by a TryFindResource call, and was not found, no exception is raised, but the returned value is null.
However no matter what I provide for an invalid key, this always returns a non null value to a BaseComponent with a class id of "UnsetValue". I can use this to differentiate between existing and non-existing resources but I am unclear why I am not getting a null value from TryFindResource when a call to FindResource with the same key to a non-existent resource throws an exception.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: TryFindResource returning non-null value on unfound reso

03 Sep 2013, 00:58

In our implementation, when TryFindResource returns the DependencyProperty::GetUnsetValue() means that resource was not found. Maybe this is a bit confusing if you are used to work with WPF. We will take a look at our code to see if it is safe to change this behavior without spoiling other parts.
 
Daki
Topic Author
Posts: 57
Joined: 16 Aug 2013, 00:48

Re: TryFindResource returning non-null value on unfound reso

03 Sep 2013, 03:06

That's fine if that is the intended behavior. I was just confused because the documentation stated otherwise. I am checking for "UnsetValue" now and treating those assets as not existing. Thanks for your reply!

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests