我正在Xamarin中创建一个应用程序。我想使用自动滚动功能,但我无法以正确的方式执行此操作。我可以手动滚动。我想要自动显示下一张图片而不滚动。 请分享您的观点和代码。
我现在使用滑块。但我想知道我是否可以做得更好。
Grid SliderGrid = new Grid ();
//SliderGrid.BackgroundColor = Color.Black;
//SliderGrid.Padding = 10;
int SlidercolumnCount = Slider.Count;
RowDefinition Sliderrow = new RowDefinition ();
SliderGrid.RowDefinitions.Add (Sliderrow);
for (int j = 0; j < SlidercolumnCount; j++) {
ColumnDefinition col = new ColumnDefinition ();
SliderGrid.ColumnDefinitions.Add (col);
}
for (int i = 0; i < SlidercolumnCount; i++) {
var vetImageCol = new Image {
HeightRequest=260,
WidthRequest=360,
BindingContext = Slider [i],
Source = Slider [i].CategoryImage,
Aspect=Aspect.AspectFill,
};
Grid.SetColumn (vetImageCol, i);
SliderGrid.Children.Add (vetImageCol);
}
var SliderContent = new ScrollView {
Orientation=ScrollOrientation.Horizontal,
HorizontalOptions=LayoutOptions.FillAndExpand,
//HeightRequest=265,
Content= SliderGrid,
};
答案 0 :(得分:1)
使用像这样的任务命令可以做到这一点:
`using(Webclient webclient = new Webclient())
{
webClient http = new Webclient();
http.Credentials = new NetworkCredential("YourUsername", "YourPassword");
}
尽管使用Task返回值而不是void可以做得更好但是你明白了
答案 1 :(得分:0)
//page view is may ui scroll view
//counter for if my image focus on last image then return on 1 img
//new PointF((float)(your image size * count),your top margin or your fram y);
int count = 0;
public async void StartTimer()
{
await Task.Delay(3000); //3 sec
count += 1;
if (count == 5)
{
count = 0;
}
var bottomOffset = new PointF((float)(UIScreen.MainScreen.Bounds.Width * count),0);
pageview.SetContentOffset(bottomOffset, animated: true);
StartTimer();
}
public override void ViewDidLoad(){
StartTimer();
}