C# 更改ListView颜色会使Xamarin列表顶部出现奇怪的文本

C# 更改ListView颜色会使Xamarin列表顶部出现奇怪的文本,c#,xaml,listview,xamarin,xamarin.forms,C#,Xaml,Listview,Xamarin,Xamarin.forms,我在代码隐藏中列出了两个名称,它们绑定到xaml文件上的ListView,在尝试将名称颜色更改为白色后,我在屏幕上看到: 代码: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" x:Class="RoseySpor

我在代码隐藏中列出了两个名称,它们绑定到xaml文件上的ListView,在尝试将名称颜色更改为白色后,我在屏幕上看到:

代码: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" x:Class="RoseySports.Invite_Page">
    <ContentPage.Content>
        <AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

            <Image AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
               Source="background.jpg" Aspect="AspectFill"/>

                <ScrollView AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1">

                <ContentView Padding="10, 40, 10, 10">

                <ListView x:Name="inviteesp" SeparatorColor="White" BackgroundColor="Transparent" Header="People">
                        <ListView.ItemTemplate>
                            <DataTemplate>

                                <TextCell Text="{Binding names}" TextColor="White"/>

                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </ContentView>
            </ScrollView>
        </AbsoluteLayout>
    </ContentPage.Content>
</ContentPage>


你确定这是正确的吗

{Binding names}
试一试

{Binding .}

您的
列表视图
项目资源
应该绑定到
名称
,在模板内部只需使用
{Binding}
指向元素,而不是该元素的属性

<ListView x:Name="inviteesp" SeparatorColor="White" BackgroundColor="Transparent" Header="People" ItemsSource="{Binding names}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding}" TextColor="White"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>


目前,您正在尝试将每个字符绑定到每个
TextCell
,而不是尝试将每个字符串绑定到每个
TextCell

,因为您使用的是未显示的
标题
,但是这个奇怪的文本,我假设问题与此相关。 你确定你有所有的NuGet软件包并且在正确的NetStandard版本上吗? 您可能应该检查您的目标版本,清理、恢复和重建您的解决方案

如果这没有帮助,请尝试为标题添加显式布局,如

<ListView x:Name="listView" Header="TEST HEADER"> <!-- this object will be the bindingcontext -->
  <ListView.HeaderTemplate >
    <DataTemplate>
      <StackLayout Orientation="Horizontal">
        <Label Text="{Binding .}"/> <!-- use the object in Header as the binding source -->
      </StackLayout>
    </DataTemplate>
  </ListView.HeaderTemplate>
  <ListView.ItemTemplate>
    your template goes here

你的模板在这里
也请查看这个xamarin论坛帖子

如果您还没有更新到Xamarin Forms 3,可以尝试更新。 检查项目中是否有对旧Xamarin表单版本的引用
文件(android、ios等)。

照你说的做了,列表以白色显示,就像我希望的那样,但我还是会把那些奇怪的文字排在最前面black@MohamedAlSabbagh你能用截图编辑你的问题吗screenshot@MohamedAlSabbagh您的页面似乎显示在某种容器中,但此处未显示。已尝试删除与列表无关的所有内容,但仍显示错误页面顶部您好,先生,您能解释一下“{Binding.}”的用法吗?我搜索了一下,但没有得到很好的答案。“”是您绑定到ItemSource的对象。在本例中,invitesp.ItemsSource=名称;那么您正在绑定“字符串”()这是xaml live player还是iOS模拟器?还有一个问题,可能很愚蠢,但我不得不问,你可以100%确认文本不在背景图像中吗?Android emulator也有问题吗?另外,您不应该使用嵌套在scrollview中的列表视图。
<ListView x:Name="listView" Header="TEST HEADER"> <!-- this object will be the bindingcontext -->
  <ListView.HeaderTemplate >
    <DataTemplate>
      <StackLayout Orientation="Horizontal">
        <Label Text="{Binding .}"/> <!-- use the object in Header as the binding source -->
      </StackLayout>
    </DataTemplate>
  </ListView.HeaderTemplate>
  <ListView.ItemTemplate>
    your template goes here