views:

1825

answers:

2

Any idea why I get this error with the following code? I'm trying to create a default template for a custom control in Silverlight 3.

IInvalid attribute value custom:CaptionControl for property TargetType. [Line: 5 Position: 23]

<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:custom="clr-namespace:Controls.Silverlight">
    <Style TargetType="custom:CaptionControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="custom:CaptionControl">
                    <Grid x:Name="RootElement">

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

.

using System.Windows;
    using System.Windows.Controls;

    namespace Controls.Silverlight
    {
        public class CaptionControl : ContentControl
        {
            public CaptionControl()
            {
                this.DefaultStyleKey = typeof(CaptionControl);
            }

            public double CaptionWidth
            {
                get { return (double)GetValue(CaptionWidthProperty); }
                set { SetValue(CaptionWidthProperty, value); }
            }

            // Using a DependencyProperty as the backing store for CaptionWidth.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty CaptionWidthProperty =
                DependencyProperty.Register("CaptionWidth", typeof(double), typeof(CaptionControl), null);


            public string Caption
            {
                get { return (string)GetValue(CaptionProperty); }
                set { SetValue(CaptionProperty, value); }
            }

            // Using a DependencyProperty as the backing store for Caption.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty CaptionProperty =
                DependencyProperty.Register("Caption", typeof(string), typeof(CaptionControl), null);


        }
    }

IInvalid attribute value custom:CaptionControl for property TargetType. [Line: 5 Position: 23]

A: 

I ran into the same issue: http://stackoverflow.com/questions/667317/silverlight-invalid-attribute-type-for-targettypextype-textblock

Spencer Ruport
I saw that post but I dont think it is the same issue. I believe the TargetType is supported/required for Custom Controls. It looks like your issue was not a custom control.
NotDan
A: 

I found the problem. I think Visual Studio somehow automatically entered the following in my App.xaml, taking the code out fixed the problem.

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Controls.Silverlight;Component/themes/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
NotDan