Search code examples
wpfresourcedictionarywindows-phone-7.1.1

Accessing a DataTemplate defined in an ancestors resource


I'm trying to access the resources of a derived abstract class (from PhoneApplicationPage) in its children. Here is a more concrete example:

Parent WPF

<phone:PhoneApplicationPage.Resources >
    <DataTemplate x:Key="EntryTemplateAbstract">
        <!-- some ui elements -->
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

Child WPF

<controls:Pivot ItemTemplate="{StaticResource EntryTemplateAbstract}" />

Duo to the nature of the DataTemplate - containing click events - I'm unable to move it into the Application resource. Although in theory this would work.

On a side note: Interestingly I cannot access the resource in either the constructor of the parent or within the child.

var test = base.Resources["EntryTemplateAbstract"]; /* <- always returns null */

Any ideas?


Solution

  • I think I solved the problem. It was caused by an oversight on my part, because I forgot to call InitializeComponent() in the base constructor.