[英]Unable to map namespaces to xmlns namespaces in xaml
我正在关注有关MVVM的教程,并且遇到了一些问题。
我创建了4个文件夹,分别代表4个不同的名称空间。 在MainPage.xaml
我使用以下代码对这些名称空间进行引用:
xmlns:viewModels="using:ViewModels"
xmlns:converters="using:Converters"
这些属性在Page
属性中。
接下来,我需要使用以下代码来使用它们:
<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>
可以在以下链接找到该教程:
问题是,出现以下错误:
名称“ ObjectExistsToVisible”在名称空间“ using:Converters”中不存在
名称“ PersonViewModel”在名称空间“ using:ViewModels”中不存在
我很确定它们确实存在。
按照要求:
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); }
}
}
}
经过Will的好评后,解决方案如下:
首先,通过Build > Clean Solution
。 接下来,通过Build > Rebuild Solution
。
这为我修复了错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.