2016-07-04 61 views
0

我有以下XAMLXamarin列表视图中显示不正确iOS上

 <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

这是iOS上的? – user3185569

+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

+0

对不起,密集但我该如何添加此代码,我会在哪里添加它? –

+0

@WelshKing以下是一步一步的指导:https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/listview/ – user3185569