DataTemplateSelector implementation not finding any resource on FindNodeResource.
Hello,
I have an implementation of a DataTemplateSelector that seems to be strugling to find the resource even if it exist using FindNodeResource.
However I have found that if I use Noesis::GUI::GetApplicationResource, it works. it seems that my dataTemplateSelector doesn't have access to the correct context for resource.
I tried to create that dataTemplate selector in various places (in my global dictionary, locally in the current page's Resource or in place directly in the ContentControl.ContentTemplateSelector.
Is this something I am doing wrong or is Noesis::GUI::GetApplicationResource() is to be used in my case? (I also have tried with the second parameter being true if that makes a difference)
(EDIT: I created this in the wrong channel, it should be General discussion. can we move it there? Sorry about that.)
Thank you!
I have an implementation of a DataTemplateSelector that seems to be strugling to find the resource even if it exist using FindNodeResource.
However I have found that if I use Noesis::GUI::GetApplicationResource, it works. it seems that my dataTemplateSelector doesn't have access to the correct context for resource.
Code: Select all
// Not working in DataTemplateSelector
BaseComponent* resourceCannotBeFound = FindNodeResource(ResourceToFind.Str(), false);
// Working
BaseComponent* ResourceFoundProperly = Noesis::GUI::GetApplicationResources()->FindNodeResource(ResourceToFind.Str(), false);
Is this something I am doing wrong or is Noesis::GUI::GetApplicationResource() is to be used in my case? (I also have tried with the second parameter being true if that makes a difference)
(EDIT: I created this in the wrong channel, it should be General discussion. can we move it there? Sorry about that.)
Thank you!
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: DataTemplateSelector implementation not finding any resource on FindNodeResource.
The DataTemplateSelector should be able to search for resources in the scope where it is defined.
So if you define it as a resource inside a dictionary, you should be able to search resources inside that dictionary. If it is not found in that scope you can continue by searching in the application resources, similar to what a StaticResource does:
Could you try that?
So if you define it as a resource inside a dictionary, you should be able to search resources inside that dictionary. If it is not found in that scope you can continue by searching in the application resources, similar to what a StaticResource does:
Code: Select all
// try find resource in the UI tree first
Ptr<BaseComponent> resource(node->FindNodeResource(mResourceKey.Str(), false));
if (resource != DependencyProperty::GetUnsetValue())
{
return resource;
}
// try find in application resources
const ResourceDictionary* app = UI::GetApplicationResources();
if (app->Find(mResourceKey.Str(), resource))
{
return resource;
}
Who is online
Users browsing this forum: No registered users and 9 guests