Skip to main content

Microsoft Silverlight

Answered Question RC0 - Style x:Key="xx" TargetType="DatePicker" causes runtime "XamlParseException: Invalid attribute value DatePicker"RSS Feed

(0)

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

RC0 - Style x:Key="xx" TargetType="DatePicker" causes runtime "XamlParseException: Invalid attribute value DatePicker"

I have a recent MSDN Magazine sample SL 2.0 application code and it defines a style for a DatePicker control starting with the line:
Style x:Key="xx" TargetType="DatePicker"

It compiles OK but generates a runtime error: "Invalid attribute value DatePicker for property TargetType."

DatePicker is defined in the Object Browser as a member of System.Windows.Controls.

Why is it Invalid to define a Style for a DatePicker in SL 2 RC0 ?
How do I use and define a style for a DatePicker control in SL 2 RC0 ?

Bill Reiss
Bill Reiss

Contributor

Contributor

4840 points

919 Posts

Silverlight MVP
Answered Question

Re: RC0 - Style x:Key="xx" TargetType="DatePicker" causes runtime "XamlParseException: Invalid attribute value DatePicker"

I think you'll need to declare the namespace in the XAML:

xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

Then refer to it as TargetType="controls:DatePicker"

the namespace "controls" can be whatever you want as long as they match. 


Bill Reiss, Coauthor of Hello! Silverlight 3
My blog (rss feed)

MyScreenNameWasTaken
MyScreen...

Member

Member

18 points

16 Posts

Re: RC0 - Style x:Key="xx" TargetType="DatePicker" causes runtime "XamlParseException: Invalid attribute value DatePicker"

Possibly exhibiting a bug which is mentioned in the readme.txt

 If the template is defined in the app.xaml (like <Application.Resources>) then move it into page.xaml under something like <UserControl.Resources> for the entire page.

 In my case, you could see it was a phoney error because the VS IDE reported the error as occurring in page.xaml when it wasn't in that page at all.

 Luke

lukepuplett.blogspot.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities