User avatar
jinfox
Topic Author
Posts: 69
Joined: 06 Apr 2019, 00:11

DataTemplateSelector implementation not finding any resource on FindNodeResource.

26 Jan 2026, 10:39

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.
// Not working in DataTemplateSelector
BaseComponent* resourceCannotBeFound = FindNodeResource(ResourceToFind.Str(), false);
// Working 
BaseComponent* ResourceFoundProperly = Noesis::GUI::GetApplicationResources()->FindNodeResource(ResourceToFind.Str(), false);
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!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: DataTemplateSelector implementation not finding any resource on FindNodeResource.

30 Jan 2026, 17:11

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:
        // 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;
        }
Could you try that?

Who is online

Users browsing this forum: No registered users and 9 guests