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

C# 减少Xamarin表单中ListView项之间的间距,c#,xaml,xamarin,xamarin.forms,cross-platform,C#,Xaml,Xamarin,Xamarin.forms,Cross Platform,我在xamarin便携应用程序中有这个列表,我似乎无法删除或至少减少项目之间的间距,也无法禁用项目选择 <ListView x:Name="ListGroups" ItemsSource="{Binding Source={x:Static local:Stash.Groups}}" HorizontalOptions="Center" > <ListView.ItemTemplate> <DataTem

我在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>

您可以尝试使用

HasUnevenRows = "true"
对于“禁用选择”,您可以按照以下步骤操作

请注意,在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>

你有这个(在Emulator/Android上)


它实际上工作得很好谢谢,您有什么禁用选择的解决方案吗@Alessandro CaliaroListView_OnItemSelected(对象发送者,SelectedItemChangedEventArgs e){(发送者作为ListView)。SelectedItem=null;}但是现在我在列表下有一个未使用的空间,我如何删除它,它将不会@Alessandro CaliaroI认为你可以使用“垂直选项”。比如“开始”。。。如果列表视图中没有“展开”,您的意思是@AlessandroCaliaro
<?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>