【问题标题】:Xamarin Forms throw Exception is not found in xmlns clr-namespace:在 xmlns clr 命名空间中找不到 Xamarin 表单抛出异常:
【发布时间】:2017-04-20 08:51:24
【问题描述】:

我在跨移动应用程序的 xamarin 表单中工作,但 IList 变量想要显示 Count 然后抛出异常。

异常详情: Xamarin.Forms.Xaml.XamlParseException:位置 19:64。在 xmlns clr-namespace:MHG.Sample.Model;assembly=MHG.Sample 中找不到类型 PersonFactory

.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/06 12:23AM GMT +3)

解决了这个问题; x:Static local: PersonFactory.People 删除本地空格:PersonFactory 关键字之间的空格。 x:Static local:PersonFactory.People

【问题讨论】:

    标签: c# .net xaml xamarin xamarin.forms


    【解决方案1】:

    第19行有错误

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

    ...请检查

    【讨论】:

      【解决方案2】:

      在您的项目设置中验证“程序集名称”是否设置为 MHG.Sample。

      在 Visual Studio 中:右键单击共享(便携式)项目,然后单击“属性”。在“库”选项卡上应该有一个带有“程序集名称”标签的框。

      在 Xamarin Studio 中:右键单击共享项目(不是 iOS 或 Android 项目)并单击选项。在“输出”屏幕上应该有一个带有“程序集名称”标签的框。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-19
        • 1970-01-01
        • 1970-01-01
        • 2022-07-29
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        相关资源
        最近更新 更多