微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 xamarin 形式的不同宽度的列表视图中显示不同长度的文本

如何解决如何在 xamarin 形式的不同宽度的列表视图中显示不同长度的文本

我有一个包含日志的列表,每个日志都有不同的大小。例如,第一个日志包含 50 个字符,下一个包含 500 个字符,我需要在列表视图项模板中显示整个 500 个字符。

请找到如下代码片段:-

<controls:CustomListView SeparatorVisibility="None"
                        ItemsSource="{Binding LogContentList}" 
                        Style="{StaticResource ListViewStyle}" SelectionMode="None" AutomationId="LogContentLabel">
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="wrappers:LogContentWrapperModel">
                                <ViewCell>
                                    <Grid VerticalOptions="FillAndExpand">
                                        <Grid.RowDeFinitions>
                                            <RowDeFinition Height="*"/>
                                            <RowDeFinition Height="1"/>
                                        </Grid.RowDeFinitions>
                                        <Label Grid.Row="0"  Padding="10,5,10,5" Text="{Binding Content}" FontSize="{StaticResource FontSizeMedium}"
                                                TextColor="{StaticResource FiordColor}" MaxLines="10" HorizontalTextAlignment="Start" HorizontalOptions="CenterandExpand"/>
                                        <BoxView Grid.Row="1" Color="Black" HeightRequest="1" HorizontalOptions="FillAndExpand" VerticalOptions="End"/>
                                    </Grid>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </controls:CustomListView>

我只需要在 listview ViewCell 中显示整个日志,但所有单元格都包含相同的宽度,我无法查看整个日志文本。

解决方法

要允许某些列表项具有多行,您应该尝试:

<ListView HasUnevenRows="True">
...
<RowDefinition Height="Auto"/>
...
<Label LineBreakMode="WordWrap"/>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。