我有以下xaml
<StackLayout Orientation="Vertical" VerticalOptions="EndAndExpand" HorizontalOptions="FillAndExpand" Margin="0,0,0,0">
<Label Text="Menu" />
<ListView x:Name="lvMenu" ItemSelected="lvMenu_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ImageSource}" Text="{Binding TitleText}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
以下c#填充它
private void PopulateMenu()
{
var menu = new List<SettingItem>()
{
new SettingItem() { ImageSource="icon.png", TitleText="Show All Jobs", TargetPageType = typeof(JobListPage) },
new SettingItem() { ImageSource="opportunities.png", TitleText="Sync Tasks", TargetPageType = typeof(SyncPage) },
new SettingItem() { ImageSource="leads.png", TitleText="Advanced Settings", TargetPageType = typeof(SettingsPage) },
new SettingItem() { ImageSource="contacts.png", TitleText="About ", TargetPageType = typeof(AboutPage) },
};
lvMenu.ItemsSource = menu;
}
一切都很好但是当它显示时我得到了
Menu
Show All Jobs
Sync Tasks
Advanced Settings
和iOS模拟器上的7个空行
答案 0 :(得分:0)
iOS上对ListView的默认行为是添加空行。
要解决此问题,您需要将ListView包装在StackPanel中,
或创建自定义渲染:
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (this.Control == null) return;
this.Control.TableFooterView = new UIView();
}
来源:Xamarin