【问题标题】:The name <> does not exist in the namespace <> (for Library project)名称 <> 在命名空间 <> 中不存在(用于库项目)
【发布时间】:2013-09-25 09:52:34
【问题描述】:

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

The name "CustomTemplate1" does not exist in the namespace "using:QSTLibrary.WIN8"

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

在特定于平台的库上,我想添加一个templated control,但是当使用add -&gt; new item -&gt; 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 是特定于平台的库

请帮我解决这个问题。

【问题讨论】:

  • 尝试注释掉有问题的样式重新编译、取消注释和构建。 Visual 使用编译后的 dll 来验证引用元素的存在。
  • @AlexandruCircus,你试过xmlns:local="clr-namespace:QSTLibrary.WIN8"吗?
  • @dkozl - 是的,我试过了,它说 QSTLibrary.WIN8 没有定义为命名空间或类似的东西
  • @Rafal - 我评论了整个 xaml、rebuid、取消注释和构建,但错误仍然存​​在。
  • @AlexandruCircus,QSTLibrary.WIN8.CustomTemplate1 与您的ResourceDictionary 在同一个程序集中吗?

标签: c# wpf xaml wpf-controls


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-04-02
    • 1970-01-01
    • 2013-02-09
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多