저는 Xamarin을 처음 사용하고 ViewModel을 뷰에 바인딩하려고하는데 아직 할 수 없었습니다.네임 스페이스 선언 오류가있는 Xamarin 폼 바인딩
다음은 코드입니다.
(모델)
namespace CadastroProdutos
{
public class Produto
{
public string Codigo { get; set; }
public string Identificacao { get; set; }
public string Tipo { get; set; }
}
}
(관찰 가능한 모델)
namespace CadastroProdutos
{
public class ObservableProduto : INotifyPropertyChanged
{
Produto produto;
public ObservableProduto()
{
}
public event PropertyChangedEventHandler PropertyChanged;
public string Codigo
{
set
{
if (!value.Equals(produto.Codigo, StringComparison.Ordinal))
{
produto.Codigo = value;
OnPropertyChanged("Codigo");
}
}
get
{
return produto.Codigo;
}
}
public string Identificacao
{
set
{
if (!value.Equals(produto.Identificacao, StringComparison.Ordinal))
{
produto.Identificacao = value;
OnPropertyChanged("Identificacao");
}
}
get
{
return produto.Identificacao;
}
}
public string Tipo
{
set
{
if (!value.Equals(produto.Tipo, StringComparison.Ordinal))
{
produto.Tipo = value;
OnPropertyChanged("Tipo");
}
}
get
{
return produto.Tipo;
}
}
void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler == null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
(뷰 모델)
namespace CadastroProdutos
{
public class ListProdutoViewModel
{
ObservableCollection<ObservableProduto> produtos;
public ListProdutoViewModel()
{
produtos = new ObservableCollection<ObservableProduto>();
}
public ObservableCollection<ObservableProduto> Produtos
{
set
{
if (value != produtos)
{
produtos = value;
}
}
get
{
return produtos;
}
}
}
}
(보기)
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CadastroProdutos;assembly=CadastroProdutos"
x:Class="CadastroProdutos.ListProduto"
Title="Listagem de Produtos">
<ContentPage.Content>
<ListView x:Name="listView" Margin="20,40,20,20" ItemsSource="{Binding Produtos}">
<ListView.BindingContext>
<local:ListProdutoViewModel />
</ListView.BindingContext>
<ListView.Header>
<StackLayout Orientation="Vertical" >
<Label Text="Produtos" HorizontalOptions="Center"/>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal" >
<TextCell Text="{Binding Identificacao}"/>
</StackLayout>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
</ContentPage>
,
오류 받기 "Xamarin.Forms.Xaml.XamlParseException 위치 10 : 6. 지역 입력 : XMLNS에서 찾을 수 없습니다 ListProdutoViewModel CLR-네임 스페이스를 : CadastroProdutos을, 조립 = CadastroProdutos " 내가 네임 스페이스 선언에 실종 무엇
사전에 감사
두 가지. 1) XamlCompilation이 켜져 있습니까? 2) bin/obj 폴더를 삭제 했습니까? –
이'xmlns : local = "clr-namespace : CadastroProdutos; assembly = CadastroProdutos"가 어떻게 조립되었는지 살펴보면 첫 번째 값이 체크 아웃 된 것으로 보이는 두 번째 값이 어셈블리라는 것을 알 수 있습니다. 어셈블리 이름이 맞습니까? CadastroProdutos라는 DLL이 있습니까? 두 값이 모두 맞으면 실제로 전체 솔루션을 다시 작성하고 정리하십시오 –