Page 1 of 1

TryFindResource returning non-null value on unfound resource

Posted: 01 Sep 2013, 21:11
by Daki
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.

Re: TryFindResource returning non-null value on unfound reso

Posted: 03 Sep 2013, 00:58
by sfernandez
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.

Re: TryFindResource returning non-null value on unfound reso

Posted: 03 Sep 2013, 03:06
by Daki
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!