c# - 名称 <> 在命名空间 <> 中不存在(对于库项目)

标签 c# wpf xaml wpf-controls

我是 C#/Windows 商店应用程序开发的新手,我遇到了一个问题: 我得到了

命名空间“using:QSTLibrary.WIN8”中不存在名称“CustomTemplate1”

我从事的项目有 2 个库(一个可移植(没有任何 GUI)和一个特定平台(Win 商店应用程序))和一个基于这 2 个库的启动项目。

在特定于平台的库上,我想添加一个模板化控件,但是当使用 add -> new item -> templated control 添加它时,Generic.xaml从自动生成的“主题”文件夹有上述错误。

这是 Generic.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:QSTLibrary.WIN8">

    <Style TargetType="local:CustomTemplate1"> //HERE IS THE PROBLEM !!!!
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:CustomTemplate1">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

这是 CustomTemplate1:​​

using System;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;

// The Templated Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234235

namespace QSTLibrary.WIN8
{
    public sealed class CustomTemplate1 : Control
    {
        public CustomTemplate1()
        {
            this.DefaultStyleKey = typeof(CustomTemplate1);
        }
    }
}

QSTLibrary.WIN8 是平台特定的库

enter image description here

请帮我解决这个问题。

最佳答案

我通过复制 Generic.xaml 的内容来解决它,删除 Generic.xaml,构建,在 Themes 文件夹下再次添加一个新的 xaml 文件(将其命名为 Generic.xaml)并粘贴 Generic 的初始内容.xaml。再次构建并工作。我的结论是,我必须首先编译包含 CustomTemplate1.cs 的库,在编译之后,库将能够添加对 CustomTemplate1.cs 的引用。由于最初的错误,lib 没有编译,所以删除有错误的文件,编译,再次添加 xaml 是我解决这个问题的方法。对我来说看起来像是 Visual Studio 错误。

关于c# - 名称 <> 在命名空间 <> 中不存在(对于库项目),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19001635/

相关文章:

c# - 使用 ItemSource 绑定(bind)访问 ListView 内的另一个数据上下文

wpf - 如何在 XAML 中放入 unicode 字符?

c# - 绑定(bind)复选框命令

c# - 如何在 C# 代码中删除 wpf TabItem 内容的默认边距

c# - 如何判断 Linq 对象是否已附加到数据上下文?

c# - 避免预处理器相关代码的 "Unreachable code"警告

c# - MVVM - 模型教程?

c# - 为什么这个 .NET Core 包与我的 PCL 不兼容?

c# - 主顶部菜单和右键单击上下文菜单之间的 WPF 共享菜单

wpf - 如何在unicode中表示分数幂?