簡體   English   中英

WPF自定義控件中的“類型引用找不到公共類型...”錯誤

[英]“The type reference cannot find a public type…” error in WPF Custom Control

我正在嘗試我的第一個WPF自定義控件。 我幾乎什么也沒做,也不會編譯。 我在generic.xaml中遇到一個錯誤,該錯誤是:“類型引用找不到名為'Filmstrip'的公共類型。第7行位置50(第7行是樣式開始標記)

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)));
        }
    }
}

我想念什么?

clr-namespaces:Unicorn.Controls應該是clr-namespace:Unicorn.Controls 單數,不是復數。

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

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

應該

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

另外,除非您使用的是程序集,否則請不要忘記使用assembly參數來引用其他程序集。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM