【发布时间】:2015-05-06 13:45:21
【问题描述】:
我正在 VC2013 中开发一个 c# Windows Phone 8.1 应用程序并偶然发现了一个奇怪的问题。
为了让我的代码更“干净”,我决定将应用程序的不同部分放入不同的文件夹中。在 c# 代码中从这些文件夹调用 XAML 页面没有问题。
但是我似乎在 XAML 代码本身中链接这些文件夹时遇到问题。例如我有以下结构:
root, Files: App.cs+xaml, Mainpage.cs+xaml
|
-- Folder: Login
|
-- Files: LoginPage.cs+xaml
-- Folder: Converters
|
-- Files: converterClass.cs
要像往常一样使用converterClass.cs 中的IValueConverter,我将以下内容放在我的 XAML 文件的标题中:
<Page
x:Class="myApp.Login.LoginPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:meinStundenplaner.Login"
xmlns:myConverter="using:myApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Styles/standardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<myConverter:DateTimeConverter x:Key="DateTimeConverter" />
... some more converters
</ResourceDictionary>
</Page.Resources>
...
现在发生了,如果我键入 <myConverter:,自动完成功能确实会像往常一样找到我的转换器类,但是在编译(正在编译)和在设备上测试时,所有转换器都不起作用,而且我在 Error -列举说法
The name 'DateTimeConverter' in namespace 'using:myApp.Converters' does not exist.
我哪里做错了?
【问题讨论】:
-
再次检查 DateTimeConverter 类是否在 myApp.Converters 命名空间中。您可能已将文件拖到文件夹中,但忘记更改 C# 代码中的命名空间。
-
另外,请检查您的转换器是否实际称为 DateTimeConverter。
-
我很困惑。根据this(以及其他参考资料),对于Windows Phone 应用程序,您应该在命名空间声明中使用
clr-namespace而不是using。您真的在编写 Windows Phone 应用程序吗?如果是这样,你为什么不使用clr-namespace?如果你这样做会发生什么?如果编辑器不知道 Windows Phone 和 Windows RT 之间的区别,因此我不会感到惊讶 -
好的,我首先尝试将其重命名为
clr-namespace,但和之前一样,当我输入命名空间,它将其更正回using。命名空间和转换器的名称正确(再次检查) -
谢谢彼得·杜尼霍!我正在编写一个作为 UniversalApp 的 win10mobile 应用程序,我需要切换到
using而不是clr-namespace。
标签: c# xaml namespaces windows-phone-8.1 converter