首页 > 解决方案 > Xamarin 形成 UWP - Listview 在加载 viewcells 时显示黑色背景

问题描述

在使用数据加载 Listview 时,黑色背景显示为加载每个视图单元格。有谁知道改变颜色或删除那种风格?

我也尝试从代码隐藏加载 Listview。有没有办法自定义这个?

参考这个截图在此处输入图像描述

黑色背景发生在视图单元加载之前。

 <ContentPage.Content>
    <StackLayout>
        <Button Pressed="Button_Pressed" Text="Back"/>
        <ListView x:Name="MyList" BackgroundColor="LightBlue" HasUnevenRows="False">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid HeightRequest="60" BackgroundColor="Bisque">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text="{Binding Name}"/>
                            <Label Grid.Column="1" Text="{Binding Quantity}"/>
                            <Label Grid.Column="2" Text="{Binding Value}"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage.Content>

代码隐藏:

 public ObservableCollection<ListItemModel> listItems { get; }
    public ListViewPage2 ()
    {
        listItems = new ObservableCollection<ListItemModel>();

        listItems.Add(new ListItemModel { Name = "First", Quantity = 1, Value = "10.00" });
        listItems.Add(new ListItemModel { Name = "Secound", Quantity = 2, Value = "20.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });
        listItems.Add(new ListItemModel { Name = "Third", Quantity = 3, Value = "30.00" });

        InitializeComponent();

        MyList.ItemsSource = listItems;
    }

    private void Button_Pressed(object sender, System.EventArgs e)
    {
        Application.Current.MainPage.Navigation.PopModalAsync();
    }

标签: xamllistviewxamarin.formsxamarin.uwpcustom-renderer

解决方案


推荐阅读