WPF: How can I retrieve the Template that was created by a ContentTemplateSelector for a specific ContentPresenter?

46 views Asked by At

In my WPF app, I'm using several ContentPresenters with a special MarkupExtension that requires access to the ContentPresenter's ContentTemplate property.

The MarkupExtension works very well, except that I just found out that if a ContentPresetner uses a ContentTemplateSelector, it doesn't set its own ContentPresenter property: rather, both the ContentPresenter and the result of the ContentTemplateSelector get saved to a private variable of the ContentPresenter class, as can be seen here: link to .Net source code for ContentPresenter.

I figured out that I can call ContentTemplateSelector.SelectTemplate() again and get the template, or keep a dictionary of selected templates inside the ContentTemplateSelector so that I can fetch the template that was geneatedfor each element, but is there a better way to do this?

0

There are 0 answers