【问题标题】:Xamarin ListView alternate column colorXamarin ListView 备用列颜色
【发布时间】:2021-12-05 13:01:17
【问题描述】:

我需要更改我的 ListView 列颜色,使其看起来像这样。

我在 Google 上搜索任何帮助,发现我可以将 BoxView 与我的 Label 放在同一列中并为 BoxView 着色

我的结果:

如您所见,我在 BoxViews 上方有一条恼人的白线,我无法将其删除。我的问题是如何删除它们?我没有设置任何填充和边距,不知道是什么问题。

<ListView x:Name="ListView" ItemTapped="ListView_OnItemTapped" ItemsSource="{Binding FilteredReports, Mode=TwoWay}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout>
                    <BoxView HeightRequest="1" Color="#EDEBE9" IsVisible="true"/>
                    <Grid HorizontalOptions="FillAndExpand">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <BoxView Color="#F7FAFC" Grid.Column="0"/>
                        <Label Grid.Column="0" FontSize="12" FontFamily="Roboto" TextColor="#162938" Text="{Binding ClientPhone}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
                        <Label Grid.Column="1" FontSize="12" FontFamily="Roboto" TextColor="#162938" Text="{Binding OfficeName}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
                        <BoxView Color="#F7FAFC" Grid.Column="2"/>
                        <Label Grid.Column="2" FontSize="12" FontFamily="Roboto" TextColor="#162938" Text="{Binding BranchName}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
                    </Grid>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

【问题讨论】:

    标签: c# xamarin


    【解决方案1】:

    您使用的是StackLayout,默认情况下它的Spacing 属性值为6。

    你应该把它设置为 0

    <ViewCell>
                    <StackLayout Spacing = "0" >
                        <BoxView HeightRequest="1" Color="#EDEBE9" IsVisible="true"/>
                        <Grid HorizontalOptions="FillAndExpand">
                            ....
                    </StackLayout>
    </ViewCell>
    

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      • 2017-04-05
      相关资源
      最近更新 更多