我正在嘗試我的第一個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)));
}
}
}
我缺少什麼?
你可能缺少'xmlns:local'聲明中的彙編規範嗎? –
xaml與自定義控件類位於同一個程序集中。 – Pete
您是否嘗試過使用非靜態公共構造函數? – Hasanain