【发布时间】:2020-05-04 22:06:56
【问题描述】:
我正在使用 CarouselView 制作照片滑块,有时照片会出现,有时照片不会出现,并显示为白色背景,并且像这样一直来回移动
Xaml 代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test01"
xmlns:forms="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
x:Class="Test01.MainPage">
<StackLayout >
<Label Text="Images " FontSize="30" Margin="20"/>
<forms:CarouselView x:Name="MainCarouselView">
<forms:CarouselView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding .}" x:Name="image" Aspect="AspectFill"/>
</DataTemplate>
</forms:CarouselView.ItemTemplate>
</forms:CarouselView>
</StackLayout>
</ContentPage>
代码背后:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Xml;
namespace Test01
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var image = new List<ImageSource>
{
ImageSource.FromResource("Test01.Images.Photo01.jpeg"),
ImageSource.FromResource("Test01.Images.Photo02.jpg"),
ImageSource.FromResource("Test01.Images.Photo03.jpg"),
ImageSource.FromResource("Test01.Images.Photo04.jpg"),
};
MainCarouselView.ItemsSource = image;
}
}
}
问题不在于照片,因为我切换了它们并一直尝试使用 1 张照片,它可以工作,然后添加其他照片,我得到了这个问题
【问题讨论】:
-
可能是图像预加载问题,特别是如果图像很大并且需要很长时间下载。考虑延迟加载它们..
-
@numbtongue 我会尝试调整它们的大小谢谢
-
它的工作。谢谢
标签: c# xamarin.forms