This is my first time ever doing anything with XAML and I'm a bit lost.
这是我第一次使用XAML做任何事情而且我有点失落。
I'm trying to add a DataTemplateSelector to my XAML page using the instructions found here. However I'm stuck on the part where I'm supposed to "declare the TaskListDataTemplateSelector as a resource". This is the example given:
我正在尝试使用此处的说明将DataTemplateSelector添加到我的XAML页面。但是我被困在我应该“将TaskListDataTemplateSelector声明为资源”的部分。这是给出的例子:
<Window.Resources>
...
<local:TaskListDataTemplateSelector x:Key="myDataTemplateSelector"/>
...
</Window.Resources>
However, the top level tag in the XAML document is <UserControl>
, and I don't see anything about Window
or Window.Resources
.
但是,XAML文档中的*标记是
Under the <UserControl>
tag is a <UserControl.Resources>
tag, but when I try to put the example code there, it gives me an error saying "The namespace prefix 'local' is not defined". I tried replacing "local" with the actual namespace, but got the same error.
在
The custom DataTemplateSelector class is in the codebehind for the XAML page, and is in the same namespace.
自定义DataTemplateSelector类位于XAML页面的代码隐藏中,并且位于同一名称空间中。
1 个解决方案
#1
0
For anyone who googled this question like I did:
对于像我一样用谷歌搜索这个问题的人:
I think I found the answer.
我想我找到了答案。
You need to define the local prefix in your XAML file.
This can be done by placing the following namespace argument in the root element:
您需要在XAML文件中定义本地前缀。这可以通过在根元素中放置以下命名空间参数来完成:
xmlns:local="clr-namespace:AssemblyName"
Change "AssemblyName" in your erm.. assembly's name.
在你的erm ..程序集的名称中更改“AssemblyName”。
#1
0
For anyone who googled this question like I did:
对于像我一样用谷歌搜索这个问题的人:
I think I found the answer.
我想我找到了答案。
You need to define the local prefix in your XAML file.
This can be done by placing the following namespace argument in the root element:
您需要在XAML文件中定义本地前缀。这可以通过在根元素中放置以下命名空间参数来完成:
xmlns:local="clr-namespace:AssemblyName"
Change "AssemblyName" in your erm.. assembly's name.
在你的erm ..程序集的名称中更改“AssemblyName”。