2016-12-05 59 views
1

我在xamarin表單中工作,用於跨移動應用程序,但IList變量需要show count,然後拋出異常。在xmlns中找不到Xamarin表單拋出異常clr-namespace:

異常詳細信息: Xamarin.Forms.Xaml.XamlParseException:位置19:64。鍵入PersonFactory中的xmlns未發現CLR-名稱空間:MHG.Sample.Model;裝配= MHG.Sample

.XAML文件內容

<?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:MHG.Sample.Model;assembly=MHG.Sample" 
      x:Class="MHG.Sample.Templates.ListViewSampleWithLocalImage"> 

    <ContentPage.Padding> 
    <OnPlatform x:TypeArguments="Thickness" iOS="0,20,0,0" /> 
    </ContentPage.Padding> 

    <ContentPage.Resources> 
    <ResourceDictionary> 
     <local:ImageSourceConverter x:Key="ImageSourceConverter" /> 
    </ResourceDictionary> 
    </ContentPage.Resources> 

    <ContentPage.Content> 
    <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"> 
     <ListView x:Name="LstPeople" ItemsSource="{ Binding . }" Footer="{ Binding Count, Source={ x:Static local: PersonFactory.People }"> 

     <ListView.Header> 
      <ContentView Padding="0,5" BackgroundColor="#fff"> 
      <Label FontSize="Medium" TextColor="#000" Text="MHG Sample" HorizontalOptions="Center" VerticalTextAlignment="Center"></Label> 
      </ContentView> 
     </ListView.Header> 

     <ListView.ItemTemplate> 
      <DataTemplate> 
      <ImageCell Text="{ Binding Fullname }" TextColor="Black" Detail="{ Binding Description }" DetailColor="Gray" ImageSource="{Binding ImageUrl, Converter={ StaticResource ImageSourceConverter }"></ImageCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 

     <ListView.FooterTemplate> 
      <DataTemplate> 
      <ContentView Padding="0,5,5,0"> 
       <Label FontSize="Medium" 
        TextColor="#666" 
        HorizontalOptions="Center" 
        HorizontalTextAlignment="End" 
        Text="{Binding ., StringFormat = '{0} kişi mevcut.' }"></Label> 
      </ContentView> 
      </DataTemplate> 
     </ListView.FooterTemplate> 
     </ListView> 
    </StackLayout> 
    </ContentPage.Content> 

</ContentPage> 

PersonFactory.cs文件內容(該文件的.xaml數據工廠)

using System; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 

namespace MHG.Sample.Model 
{ 
    public static class PersonFactory 
    { 
     public static List<Person> People = new List<Person>(); 

     static PersonFactory() 
     { 
      var list = new ObservableCollection<Person>(); 
      for (var i = 0; i < new Random().Next(10, 100); i++) 
      { 
       var person = new Person(i, Faker.Name.First(), Faker.Name.Last(), $"{new Random().Next(1, 10)}.jpg") 
       { 
        Description = Faker.Lorem.Sentence() 
       }; 
       list.Add(person); 
      } 
      People.AddRange(list); 
     } 
    } 
} 

編輯(2016年12月6日上午12時23 GMT +3)

解決了這個問題; x:Static local: PersonFactory.People 刪除本地空間:介於PersonFactory關鍵字之間。 x:Static local:PersonFactory.People

回答

2

它具有線路故障19

<ListView x:Name="LstPeople" ItemsSource="{ Binding . }" Footer="{ Binding Count, Source={ x:Static local: PersonFactory.People }"> 

...請檢查

1

驗證您的項目設置中「Assembly name」設置爲MHG.Sample。

在Visual Studio中:右鍵單擊共享(可移植)項目,然後單擊「屬性」。在「庫」選項卡上應該有一個帶有「組件名稱」標籤的框。

OR

在Xamarin演播室:右鍵點擊共享項目(不是iOS或Android項目),然後單擊選項。在「輸出」屏幕上,應該有一個帶有「組件名稱」標籤的框。