[英]Xamarin Listview within Stacklayout displays incorrectly on iOS
I have the following xaml 我有以下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>
The following c# populates it 以下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;
}
Its all good but when it displays I get 一切都很好,但是当它显示时我得到了
Menu
Show All Jobs
Sync Tasks
Advanced Settings
and 7 blank lines on an iOS emulator 和7个空白行在iOS模拟器上
The default behaviour on iOS for a ListView is to add the empty rows. ListView在iOS上的默认行为是添加空行。
To overcome this, you need to wrap your ListView in a StackPanel, 为了解决这个问题,您需要将ListView包装在StackPanel中,
Or Create a custom Rendered: 或创建自定义渲染:
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (this.Control == null) return;
this.Control.TableFooterView = new UIView();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.