我正在编写Xamarin表单应用程序,在ListView中显示用户注释。
问题是它在Android上正确显示但在iOS上它是开箱即用的(如屏幕截图所示)
在收集信息的异步网络请求后添加这些项目,我不知道这是否会影响它。
Android屏幕
iOS屏幕
我的XAML
<local:PostListView x:Name="MessageView" HasUnevenRows="True" IsPullToRefreshEnabled="True" Refreshing="MessageView_Refreshing" SeparatorVisibility="None" BackgroundColor="#7ed6df">
<ListView.ItemTemplate>
<DataTemplate>
<local:PostViewCell>
<StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
<Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>
</Image>
<Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
<StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
<Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>
</Image>
<Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
</StackLayout>
</StackLayout>
</local:PostViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</local:PostListView>
PostViewCell.cs
using SocialNetwork.iOS.Renderers;
using SocialNetwork.Renderers;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(PostViewCell), typeof(PostViewCelliOS))]
namespace SocialNetwork.iOS.Renderers
{
public class PostViewCelliOS : ViewCellRenderer
{
public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
{
var cell = base.GetCell(item, reusableCell, tv);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
return cell;
}
}
}
答案 0 :(得分:1)
您可以尝试创建一个包含您的内容的StackLayout,如:
<local:PostViewCell>
<StackLayout>
<StackLayout x:Name="MessageLayout" BackgroundColor="White" Margin="10, 10, 10, 10" Padding="10, 10, 15, 10">
<Image Source="options_icon.png" HeightRequest="18" HorizontalOptions="End" Margin="5, 0, 5, 0" IsVisible="{Binding ShowBanners}">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OptionClick}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>
</Image>
<Label Text="{Binding Body}" HorizontalOptions="CenterAndExpand" TextColor="{Binding BodyColor}" FontSize="15" Margin="0, 10, 0, 10"/>
<StackLayout x:Name="MessageFooter" Orientation="Horizontal" IsVisible="{Binding ShowBanners}">
<Image x:Name="LikeSource" Source="{Binding LikeImageSource}" HeightRequest="20" HorizontalOptions="StartAndExpand" Margin="0, 0, 10, 0">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LikeClick}" CommandParameter="{Binding .}"/>
</Image.GestureRecognizers>
</Image>
<Label Text="{Binding Timestamp}" TextColor="Black" FontSize="10" HorizontalOptions="EndAndExpand"/>
</StackLayout>
</StackLayout>
</StackLayout>
</local:PostViewCell>