2011-08-31 297 views
0

我正在嘗試我的第一個WPF自定義控件。我幾乎沒有做任何事情,它不會編譯。我得到一個錯誤在我的generic.xaml,上面寫着:「類型引用無法找到名爲‘幻燈’公共型線7的位置50(7號線是風格開始標籤)「類型引用無法找到公共類型...」在WPF自定義控件中的錯誤

Generic.xaml:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespaces:Unicorn.Controls"> 
    <Style TargetType="{x:Type local:Filmstrip}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:Filmstrip}"> 
        <Border Background="{TemplateBinding Background}" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}"> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

Filmstrip.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 

namespace Unicorn.Controls 
{ 
    public class Filmstrip : Control 
    { 
     static Filmstrip() 
     { 
      DefaultStyleKeyProperty.OverrideMetadata(typeof(Filmstrip), new FrameworkPropertyMetadata(typeof(Filmstrip))); 
     } 
    } 
} 

我缺少什麼?

+0

你可能缺少'xmlns:local'聲明中的彙編規範嗎? –

+0

xaml與自定義控件類位於同一個程序集中。 – Pete

+1

您是否嘗試過使用非靜態公共構造函數? – Hasanain

回答

3

clr-namespaces:Unicorn.Controls應該是clr-namespace:Unicorn.Controls,奇異,不是複數。

2

看來你的xaml中有語法錯誤。下面一行:

xmlns:local="clr-namespaces:Unicorn.Controls" 

應該

xmlns:local="clr-namespace:Unicorn.Controls" 

而且,除非這是你的工作中不要忘記使用裝配參數引用其他組件的裝配。

相關問題