【问题标题】:Adding a background image to a list view Xamarin.Forms将背景图像添加到列表视图 Xamarin.Forms
【发布时间】:2018-12-23 07:33:48
【问题描述】:

我已经为此苦苦挣扎了一段时间。我有一个简单的列表视图,它使用数据模型来提取数据。我想要的只是将屏幕大小的图像放在背景中

<ContentPage Padding="0,-20,0,0" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="xxxxxxxx.Pages.PrayersByCategory">
<ContentPage.Content>
    <ListView RowHeight="55"  x:Name="lv_prayers_categories_page" VerticalOptions="FillAndExpand" HasUnevenRows="false" SelectedItem="Handle_ItemSelected" BackgroundColor="Transparent" SeparatorVisibility="None">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                        <Grid x:Name="cellGrid" Padding="15">
                        <Grid.ColumnDefinition></Grid.ColumnDefinition>
                        <Label x:Name="lblPrayerCategory" Text = "{Binding prayerCategory}" FontSize="16" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
                        <Label x:Name="lblPrayerCount" Text = "{Binding prayerCategoryID}" FontSize="16" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2"/></Grid></ViewCell>        
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

【问题讨论】:

  • 使用 ContentPage 的 BackgroundImage 属性

标签: image listview xamarin.forms


【解决方案1】:

如果您的列表视图填满页面,您可以设置 ContentPage 背景颜色:

    <ContentPage Padding="0,-20,0,0" 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="xxxxxxxx.Pages.PrayersByCategory"
    BackgroundImage="star_outline.png">

【讨论】:

  • 我在 iOS 项目的资源下有我的图像,并且列表视图具有透明背景色,但我看不到我的图像。如果您将图像称为 BackgroundImage,是否需要将图像放入其他位置。
  • @logixologist 能不能把图片目录截图一下,可能你的图片没有正确添加
猜你喜欢
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
相关资源
最近更新 更多