1
I have a ListView
and within it I have a CarouselView
by the name of CarrosselDeImagens
, but in code Behind I can’t access the CarouselView
. Kind of: CarrosselDeImagens.ItemSource = listaImagens
.
How could I access carouselview inside 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>
Model:
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; } }
}
Method of loading
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;
}
Ola Diego Rafael Souza, I edited my question with the codex XAML. If you can give me a light?
– user114682
My template brings up to six strings with the url of the images that are in an api with the data of the classifieds. I put all the code for you to see.
– user114682
It is in the Behind code of the page. No viewmodel I am not using MVVM for malpractice... Hehehe... It’s been a while since I’ve touched Xamarin and a lot has changed and I’m a little lost... Hehehe... The code is not all mixed as in the question is why I could not format right.
– user114682