Problem with OnApplyTemplates in Prism?

May 14, 2008 at 6:35 PM

Problem summary: I don't see where OnApplyTemplates is getting called for a custom control.

Detail: I have a custom templated control that is being hosted in a region but the overridden OnApplyTemplates is not getting called like it should be or at least like I think it should be.  I double checked and the same is true in the UIComposition project.

I modified the file .\Prism\Source\QuickStarts\UIComposition\UIComposition.Infrastructure\Controls\DeckPanel.cs to be as follows

    public class DeckPanel : Grid
        public DeckPanel()
            : base()
        }  // <- breakpoint here

        public override void OnApplyTemplate()
            base.OnApplyTemplate();    // <- breakpoint here

With breakpoints on the noted lines.

The constructor is in fact being called but OnApplyTemplate() is not.  I am not sure why but it appears to interfere with using templated custom controls. 

Of course I am still pretty new to WPF so I could be totally off base.  If so, could you point me in the right direction of how to get a templated custom control to properly retrieve templates and styles when inside prism?


May 23, 2008 at 4:24 PM
The DeckPanel has actually been removed in the latest version of the UIComposition spike. We are now using a content control with data binding to acheive the same behavior.

Could you describe the scenario in your own app where you are trying to do this and how that element is being used in the app (i.e. just declared in XAML, or created some other way)?