I'm following a tutorial on MVVM and am having some issues.
I created 4 folders which represent 4 different namespaces. In my MainPage.xaml
I'm making a reference to these namespaces using the following code:
xmlns:viewModels="using:ViewModels"
xmlns:converters="using:Converters"
These properties are in the Page
attributes.
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"
The name "PersonViewModel" does not exist in the namespace "using:ViewModels"
I'm pretty sure that they do exist.
As requested:
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:
First, clean the solution via Build > Clean Solution
. Next, rebuild the solution via Build > Rebuild Solution
.
This fixed the errors for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.