【发布时间】: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 -> 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 是特定于平台的库
请帮我解决这个问题。
【问题讨论】:
-
尝试注释掉有问题的样式重新编译、取消注释和构建。 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