2017-04-12 92 views
0

我xamarin便携式应用有这个名单,我不能似乎能够消除或至少减少项目之间的间距,并禁用项目选择也。减少Xamarin的ListView项目之间的间距形成

<ListView x:Name="ListGroups" 
      ItemsSource="{Binding Source={x:Static local:Stash.Groups}}" 
      HorizontalOptions="Center" > 
    <ListView.ItemTemplate> 
    <DataTemplate > 
     <ViewCell> 
      <Label Text="{Binding Name}" TextColor="Aqua" FontSize="10" HorizontalOptions="Center" /> 
     </ViewCell> 
    </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

那么一些标签

<Label Text="If you feel you're missing" 
      FontSize="15" 
      VerticalOptions="Center" 
      HorizontalOptions="Center" 
      TextColor="White" 
      /> 
    <Label Text="a group or two, please contact" 
       FontSize="15" 
      VerticalOptions="Center" 
      HorizontalOptions="Center" 
      TextColor="White" 
      /> 
    <Label Text="your manager" 
      FontSize="15" 
      VerticalOptions="Center" 
      HorizontalOptions="Center" 
      TextColor="White" 
      /> 


    </StackLayout> 

ImageBackgroundcolor

回答

1

你可以用

HasUnevenRows = "true" 

尝试 “不可选择” 可以按照以下

Disabling selection

SelectionDemoList.ItemSelected += (sender, e) => { 
    ((ListView)sender).SelectedItem = null; 
}; 

需要注意的是在Windows Phone上,一些细胞,包括SwitchCell不响应选择更新其可视状态。

为了减少ListView的高度,你可以使用一个网格。这是一个示例

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="TestRelativeLayout.MyPage2"> 
    <ContentPage.Content> 
     <StackLayout> 
        <StackLayout> 
             <Grid VerticalOptions = "FillAndExpand"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="50" /> 
        <RowDefinition/> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="10*" /> 
        <ColumnDefinition Width = "1*"/> 
        </Grid.ColumnDefinitions> 
      <Entry Placeholder="MyEntry" Grid.Column = "0" Grid.Row="0" Grid.ColumnSpan = "2"/> 
      <Image Source="icon.png" Grid.Column="1" Grid.Row = "0" Margin="0,0,20,0"/> 
       </Grid> 
     </StackLayout> 
           <Grid VerticalOptions = "FillAndExpand"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="150" /> 
        <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="*" /> 
        </Grid.ColumnDefinitions> 
         <ListView x:Name="ListGroups" 
        Grid.Row = "0" 
        Grid.Column = "0" 
      ItemsSource="{Binding myList}" 
      HorizontalOptions="Center" 
       VerticalOptions="Start" 
       BackgroundColor = "Red"> 
    <ListView.ItemTemplate> 
    <DataTemplate > 
     <ViewCell> 
      <Label Text="{Binding Name}" TextColor="Aqua" FontSize="10" HorizontalOptions="Center" /> 
     </ViewCell> 
    </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
      <StackLayout Grid.Row = "1" Grid.Column = "0" > 
      <Label Text="If you feel you're missing" 
      FontSize="15" 
      VerticalOptions="StartAndExpand" 
      HorizontalOptions="Center" 
      TextColor="Black" 
      /> 
    <Label Text="a group or two, please contact" 
       FontSize="15" 
      VerticalOptions="StartAndExpand" 
      HorizontalOptions="Center" 
      TextColor="Black" 
      /> 
    <Label Text="your manager" 
      FontSize="15" 
      VerticalOptions="StartAndExpand" 
      HorizontalOptions="Center" 
      TextColor="Black" 
      /> 
      </StackLayout> 
      </Grid> 

     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

你有这个(在模拟器/安卓)

Sample

+0

实际工作完美感谢你,你对禁止选择任何解决方案? @Alessandro Caliaro – Adam

+0

ListView_OnItemSelected(对象发件人,SelectedItemChangedEventArgs E) { (发送者作为ListView的).SelectedItem = NULL; } – Dilmah

+0

谢谢@Alessandro Caliaro它的作品 – Adam

相关问题