0

知道为什么我使用以下代码收到此错误吗?我正在尝试为 Silverlight 3 中的自定义控件创建默认模板。

IInvalid 属性值自定义:属性 TargetType 的 CaptionControl。[行:5 位置: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 属性值自定义:属性 TargetType 的 CaptionControl。[行:5 位置:23]

4

1 回答 1

0

我发现了问题。我认为 Visual Studio 以某种方式自动在我的 App.xaml 中输入了以下内容,从而解决了问题。

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Controls.Silverlight;Component/themes/generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
于 2009-05-21T03:17:48.703 回答