Carrusel (Automatico)

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

----------------------MainPage.

xaml----------------
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Carusel.MainPage">

<ContentPage>
<StackLayout VerticalOptions="Center">
<Label Text="Nombre" FontSize="Large"></Label>
<Image Source="https://tinyurl.com/8d495yn6"></Image>
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout VerticalOptions="Center">
<Label Text="Nombre" FontSize="Large"></Label>
<Image Source="https://tinyurl.com/wrye9yvw"></Image>
</StackLayout>
</ContentPage>
<ContentPage>
<StackLayout VerticalOptions="Center">
<Label Text="Nombre" FontSize="Large"></Label>
<Image Source="https://tinyurl.com/v9av3kyu"></Image>
</StackLayout>
</ContentPage>

</CarouselPage>
----------------------MainPage.xaml.cs-----------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Carusel
{
public partial class MainPage : CarouselPage
{
public MainPage()
{
InitializeComponent();
}
}
}
----------------------CarruselView.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"
x:Class="Carusel.CaruselView">
<ContentPage.Content>
<StackLayout Padding="10">
<CarouselView x:Name="Carousel" IndicatorView="Indicador"
HeightRequest="200">
<CarouselView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Url}" Aspect="AspectFill"></Image>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView x:Name="Indicador"
IndicatorColor="Gray"
SelectedIndicatorColor="DarkGray"
IndicatorSize="10"
VerticalOptions="Center"></IndicatorView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
----------------------CarruselView.xaml.cs------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Carusel
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CaruselView : ContentPage
{
public CaruselView ()
{
InitializeComponent ();
List<Image> images = new List<Image>()
{
new Image() {Title = "Naruto", Url =
"https://tinyurl.com/3jkckys2"},

new Image() { Title = "Hunter x Hunter", Url =


"https://tinyurl.com/5fabn6za"},

new Image() { Title = "Bleach", Url =


"https://tinyurl.com/2p9scpad"}
};
Carousel.ItemsSource = images;
Device.StartTimer(TimeSpan.FromSeconds(5), (Func<bool>)(() =>
{
Carousel.Position = (Carousel.Position + 1) % images.Count;
return true;
}));
}
}
}
----------------------ArchivoClase<<<<<Image.cs>>>>>>------------------------

using System;
using System.Collections.Generic;
using System.Text;

namespace Carusel
{
class Image
{
public string Title { get; set; }
public string Url { get; set; }
}
}

You might also like