I have a ListView
and inside it I have a CarouselView
with the name of CarrosselDeImagens
, but in the code behind I can not access the CarouselView
. Type like this: CarrosselDeImagens.ItemSource = listaImagens
.
How could I access the carouselview within a listview?
Code XAML
:
<ListView x:Name="LstClassificados" HasUnevenRows="true" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<ContentView BackgroundColor="White">
<Frame BorderColor="#49c1ff"
Margin="10"
CornerRadius="10">
<StackLayout>
<Label Text="{Binding titulo}"
FontSize="Medium"
FontAttributes="Bold"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
HorizontalOptions="Center" />
<control:CarouselViewControl Grid.Column="0"
Grid.Row="1"
x:Name="CarrosselDeImagens"
ShowIndicators="True"
Orientation="Horizontal"
WidthRequest="300"
HeightRequest="300">
<control:CarouselViewControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding .}" />
</DataTemplate>
</control:CarouselViewControl.ItemTemplate>
</control:CarouselViewControl>
</StackLayout>
</Frame>
</ContentView>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Template:
public class Classificado
{
public int IdClassificado { get; set; }
public string id { get; set; }
public string titulo { get; set; }
public string texto { get; set; }
public string contato_email { get; set; }
public string contato_tel { get; set; }
public string contato_hora { get; set; }
public string pago { get; set; }
public string categ { get; set; }
public string subcateg { get; set; }
private string _img_link1;
public string img_link1 { get { return "http://" + _img_link1; } set { _img_link1 = value; } }
private string _img_link2;
public string img_link2 { get { return "http://" + _img_link2; } set { _img_link2 = value; } }
private string _img_link3;
public string img_link3 { get { return "http://" + _img_link3; } set { _img_link3 = value; } }
private string _img_link4;
public string img_link4 { get { return "http://" + _img_link4; } set { _img_link4 = value; } }
private string _img_link5;
public string img_link5 { get { return "http://" + _img_link5; } set { _img_link5 = value; } }
private string _img_link6;
public string img_link6 { get { return "http://" + _img_link6; } set { _img_link6 = value; } }
}
Upload method
private void CarregarCarrossel()
{
var linkImagens = new List<string>
{
linkImagem.img_link1,
linkImagem.img_link2,
linkImagem.img_link3,
linkImagem.img_link4,
linkImagem.img_link5,
linkImagem.img_link6
};
List<string> imagens = new List<string>();
foreach (var link in linkImagens)
{
string flag = "http://";
if (link != flag)
imagens.Add(link);
}
CarrosselDeImagens.ItemsSource = imagens;
}