[英]Unable to map namespaces to xmlns namespaces in xaml
I'm following a tutorial on MVVM and am having some issues. 我正在关注有关MVVM的教程,并且遇到了一些问题。
I created 4 folders which represent 4 different namespaces. 我创建了4个文件夹,分别代表4个不同的名称空间。 In my
MainPage.xaml
I'm making a reference to these namespaces using the following code: 在
MainPage.xaml
我使用以下代码对这些名称空间进行引用:
xmlns:viewModels="using:ViewModels"
xmlns:converters="using:Converters"
These properties are in the Page
attributes. 这些属性在
Page
属性中。
Next, I need to use those using the following code: 接下来,我需要使用以下代码来使用它们:
<Page.Resources>
<converters:ObjectExistsToVisible x:Key="ObjectExistsToVisible" />
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Vertical">
<ListView x:Name="MainList"
ItemsSource="{x:Bind Organization.People, Mode=OneWay}"
SelectedIndex="{x:Bind Organization.SelectedIndex, Mode=TwoWay}"
MinWidth="250" Margin="5">
<ListView.ItemTemplate>
<!-- The error is with x:DataType="" -->
<DataTemplate x:DataType="viewModels:PersonViewModel" >
<TextBlock Text="{x:Bind Name, Mode=OneWay}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Content="Add" Click="{x:Bind Organization.Add}" Margin="5"/>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Vertical">
<TextBox
Text="{x:Bind Organization.SelectedPerson.Name, Mode=TwoWay, FallbackValue=''}"
Margin="5" />
<TextBox
Text="{x:Bind Organization.SelectedPerson.Age, Mode=TwoWay, FallbackValue='0'}"
Margin="5" />
<Button Content="Delete" Click="{x:Bind Organization.Delete}" Margin="5" />
</StackPanel>
</Grid>
The tutorial can be found at: this link 可以在以下链接找到该教程:
The problem is, I'm getting the following errors: 问题是,出现以下错误:
The name "ObjectExistsToVisible" does not exist in the namespace "using:Converters"
名称“ ObjectExistsToVisible”在名称空间“ using:Converters”中不存在
The name "PersonViewModel" does not exist in the namespace "using:ViewModels"
名称“ PersonViewModel”在名称空间“ using:ViewModels”中不存在
I'm pretty sure that they do exist. 我很确定它们确实存在。
As requested: 按照要求:
PersonViewModel: PersonViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Data;
namespace ViewModels
{
public class PersonViewModel : NotificationBase<Person>
{
public PersonViewModel(Person person = null) : base(person) { }
public String Name
{
get { return This.Name; }
set { SetProperty(This.Name, value, () => This.Name = value); }
}
public int Age
{
get { return This.Age; }
set { SetProperty(This.Age, value, () => This.Age = value); }
}
}
}
After a great comment from Will, the solution is as follows: 经过Will的好评后,解决方案如下:
First, clean the solution via Build > Clean Solution
. 首先,通过
Build > Clean Solution
。 Next, rebuild the solution via Build > Rebuild Solution
. 接下来,通过
Build > Rebuild Solution
。
This fixed the errors for me. 这为我修复了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.