TryFindResource returning non-null value on unfound resource
I am trying to gracefully handle loading resources which may not exist within my xaml files.
According to the documentation:
According to the documentation:
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 FindResource call, and was not found, an exception is raised.
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.If a resource was requested by a TryFindResource call, and was not found, no exception is raised, but the returned value is null.
-
-
sfernandez
Site Admin
- Posts: 2056
- Joined:
Re: TryFindResource returning non-null value on unfound reso
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
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: No registered users and 1 guest