2009-05-20 177 views
0

任何想法爲什麼我得到這個錯誤與下面的代碼?我試圖在Silverlight 3中爲自定義控件創建默認模板。Silverlight自定義控件中屬性TargetType的屬性值無效

IInvalid屬性值custom:CaptionControl屬性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屬性值custom:CaptionControl屬性TargetType。 [Line:5 Position:23]

回答

0

我發現了這個問題。我認爲Visual Studio以某種方式自動在我的App.xaml中輸入以下內容,並將代碼解決了問題。

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

那麼,與主題或..的問題?它以前如何? – VoodooChild 2010-11-23 19:18:58