I’ve a ContentPage which have a CollectionView which shows results from a table, the code works perfectly fine
, the results are loaded and displayed.
But when I add this ContentPage to a Caroussel, it doesn't works anymore
, it loads the results, but doesn’t display in UI
This’s my XAML code from my Carousel (partial):
<!-- Carousel View -->
<CarouselView x:Name="carouselView"
Grid.Row="4"
IsBounceEnabled="True"
IsScrollAnimated="True"
IsSwipeEnabled="True"
Loop="False"
IndicatorView="indicadorView"
HorizontalOptions="FillAndExpand"
CurrentItemChanged="OnCurrentItemChanged"
Margin="0,0,0,10">
<CarouselView.ItemsSource>
<x:Array Type="{x:Type ContentPage}">
<local:ValoresAditivo Title="Valores"/>
<local:TabelaDocumentos Title="Documentos"/>
<local:TabelaDevolvidos Title="Devolvidos"/>
<local:TabelaPagamentos Title="Pagamentos"/>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<VerticalStackLayout>
<Label Text="{Binding Title}"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
FontSize="Large"
TextColor="White"/>
</VerticalStackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
This’s my c# code from my Caroussel (partial):
public ObservableCollection<ContentPage> Pages { get; set; }
public ValoresAditivo ValoresAditivoPage { get; set; }
public TabelaDocumentos TabelaDocumentosPage { get; set; }
public TabelaDevolvidos TabelaDevolvidosPage { get; set; }
public TabelaPagamentos TabelaPagamentosPage { get; set; }
public AditivosCarousel()
{
InitializeComponent();
// Outras Páginas
ValoresAditivoPage = new ValoresAditivo();
TabelaDocumentosPage = new TabelaDocumentos();
TabelaDevolvidosPage = new TabelaDevolvidos();
TabelaPagamentosPage = new TabelaPagamentos();
Pages =
[
ValoresAditivoPage,
TabelaDocumentosPage,
TabelaDevolvidosPage,
TabelaPagamentosPage
];
carouselView.ItemsSource = Pages;
}
private void OnCurrentItemChanged(object sender, CurrentItemChangedEventArgs e)
{
var selectedPage = e.CurrentItem as ContentPage;
if (selectedPage != null)
{
contentArea.Content = selectedPage.Content;
// Se for resumo contrato, então chamar função para carregar dados
// if (selectedPage is TabelaDocumentos tabelaDocumentosPage)
// {
// tabelaDocumentosPage.BindingContext = tabelaDocumentosPage.viewModel;
// LoadTabela(16);
// }
}
}
private async void NroAditivoValueChanged(object sender, ValueChangedEventArgs e)
{
// Verifique se o componente foi inicializado e se o entryNumeroCliente contém um número não nulo
if (entryNumeroAdt != null && !string.IsNullOrEmpty(entryNumeroAdt.Text) && int.TryParse(entryNumeroAdt.Text, out _))
{
if (resultsAdts != null)
{
var filteredResults = resultsAdts.Results.Where(r => r.Aditivo == stepperNumeroAdt.Value).ToList();
if (filteredResults.Any())
{
// Carregar todos os dados do aditivo
var aditivo = filteredResults.First();
var ID_Aditivo = aditivo.ID_Aditivo ?? 0;
// Exemplo de como você pode atualizar os controles com os valores filtrados
ValoresAditivoPage.CarregarValores(Convert.ToInt64(stepperNumeroAdt.Value), aditivo);
// Carregar Documentos
await TabelaDocumentosPage.LoadTabela(ID_Aditivo);
// Carregar Devolvidos
await TabelaDevolvidosPage.LoadTabela(ID_Aditivo);
}
else
{
Debug.WriteLine("Nenhum resultado encontrado com Aditivo igual a " + stepperNumeroAdt.Value + ".");
}
}
else
{
Debug.WriteLine("resultsAdts não foi inicializado.");
}
}
}
The load function is at this line await TabelaDocumentosPage.LoadTabela(ID_Aditivo);
ContentPage inside Caroussel (doesn’t works):
ContentPage not inside Caroussel (works):