【发布时间】:2021-10-23 11:14:24
【问题描述】:
我正在尝试在 Xamarin.Forms 附带的标准 ListView 组件周围添加 1px 边框,而 BorderColor 属性似乎不存在。
我如何做到这一点?
【问题讨论】:
标签: listview xamarin xamarin.forms
我正在尝试在 Xamarin.Forms 附带的标准 ListView 组件周围添加 1px 边框,而 BorderColor 属性似乎不存在。
我如何做到这一点?
【问题讨论】:
标签: listview xamarin xamarin.forms
您可以使用填充让框架充当边框。请记住关闭阴影。
<Frame BackgroundColor="Black" Padding="1" CornerRadius="0" HasShadow="False">
<!-- Your ListView here... make sure to set a BackgroundColor -->
</Frame>
【讨论】:
您也可以使用 BoxView。并使用RowHeight 属性设置HeightRequest 属性来移除listview 底部的空白区域。
Xaml:
<Grid Padding="5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<BoxView BackgroundColor="Green" HeightRequest="5"></BoxView>
<ListView x:Name="listview" BackgroundColor="White" RowHeight="40" ItemsSource="{Binding Names}" Margin="5" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}"></Label>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
后面的代码:
public partial class Page5 : ContentPage
{
public ObservableCollection<Info> Names { get; set; }
public Page5()
{
InitializeComponent();
Names = new ObservableCollection<Info>()
{
new Info(){ Name="A"},
new Info(){ Name="B"},
new Info(){ Name="C"},
new Info(){ Name="D"},
new Info(){ Name="E"},
new Info(){ Name="F"},
new Info(){ Name="G"},
};
listview.HeightRequest = listview.RowHeight * Names.Count;
this.BindingContext = this;
}
}
public class Info
{
public string Name { get; set; }
}
【讨论】: