减少Xamarin表单中ListView项之间的间距

时间:2017-04-12 12:15:19

标签: c# xaml xamarin xamarin.forms cross-platform

我在xamarin便携式应用程序中有此列表,我似乎无法删除或至少减少项目之间的间距,并禁用项目选择。

<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 个答案:

答案 0 :(得分: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>

你有这个(在模拟器/ Android上)

Sample