tags:

views:

3132

answers:

4

Hi

I have a WPF calendar control and the template for the day has a property called

cal.DayTemplate =

I have created a dictionary file contaning my control template for the day of the calendar

But I am not sure how to load it into the DayTemplate property.

I have added my dictionary to the Application.Resources in App.xaml

the x:Key to my control template is x:Key="DayTemplate"

So I though to load it this would work

cal.DayTemplate = new DataTemplate("DayTemplate");

Malcolm

A: 

Edit: Oops. Been a while since I had to do this.

I believe you want:

cal.DayTemplate = (DataTemplate)Application.Current.FindResource("DayTemplate");

See if that works.

Matt Hamilton
A: 

I get this error using that code. I am loading from a seperate class

Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Application.FindResource(object)' C:\Users\Malcolm\Documents\Visual Studio 2008\Projects\PopUpHelp\PopUpHelp\PageControls\Calender\CalenderPage.cs 94 45 PopUpHelp

Malcolm
A: 

I need to get a reference to my applicatino object right?

How do i do that from a class??

Malcolm
A: 

Now I get a can't cast Controltemplate to DataTemplate.

Should I be creating a DataTemplate in by dictionary.

When I do this and run the app I get an error as it trying to load the cal control

Seems like for each day it errors in a loop

hmmm

Malcolm
Hey Malcolm - you can leave comments on answers or just edit your original question, rather than posting new answers. If DayTemplate is a control template then just cast to a ControlTemplate instead. Should work.
Matt Hamilton