Click here to Skip to main content
15,887,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
from main page navigating to details page on click event
on details page remote images are being loaded in list view
I'm loading list view on list.loaded event to start image downloading on details page
but when I click on button. main page hold for 5 seconds. according to my logic it should not wait or hold for x nomber of seconds, yes it downloads images first on main page then goes to details page.
according to my code, main page should navigate to details page and when list view is loaded then details page should come up with remote images.
why i am facing this behaviour, any help is much appreciated.
regards

What I have tried:

click event from main page
C#
private async void OnInfinixClicked(object sender,EventArgs e)
{
    Brands MyBrands = new Brands { name = "infinix" };
    Navigation.PushModalAsync(new details(MyBrands));
}


details page code behind
C#
namespace MobilePrice;

public partial class details : ContentPage
{
    public ObservableCollection<test> Names { get; set; } = new ObservableCollection<test>();
    public details(Brands b)
	{
        InitializeComponent();
        BindingContext = this;
        mylistview.Loaded += (s, e) => 
        { 
            mylabel.Text = "my list view loaded";
            var filepath = System.IO.Path.Combine(FileSystem.Current.AppDataDirectory, "filenames.txt");
            var retrievefiles = new WebClient();
            retrievefiles.DownloadFile("https://maliksuhail.github.io/mobileprices/" + b.name.ToString() + "/filenames.txt", filepath);
            Debug.WriteLine($"File Path: {filepath}");
            StreamReader Textfile = new StreamReader(@filepath);
            string line;
            while ((line = Textfile.ReadLine()) != null)
            {
                Debug.WriteLine(line);
                Names.Add(new test { ImageUrl = "https://maliksuhail.github.io/mobileprices/" + b.name.ToString() + "/" + line });
            }
            //myAds.LoadAd();
        };

    }
}

details page xaml
XAML
<Label x:Name="mylabel"></Label>
        <ListView x:Name="mylistview" ItemsSource="{Binding Names}" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell >
                        <!--<HorizontalStackLayout Padding="-25">-->
                            <Image Source="{Binding ImageUrl}"
                                                                  SemanticProperties.Description="{Binding ImageUrl}"
                                   Aspect="AspectFit"
                   VerticalOptions="Start" />
                        <!--</HorizontalStackLayout>-->
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
Posted
Updated 2-Jul-23 20:34pm
v2
Comments
Graeme_Grant 2-Jul-23 20:57pm    
[moved]

1 solution

There is not enough code here to start looking at the issue. Best thing you can do is set breakpoints and inspect to see what is happening. IF I were to look at a problem, this is the first thing that I would do.

if you having difficulty in debugging, check this link: Debugging on Windows - .NET MAUI | Microsoft Learn[^]
 
Share this answer
 
Comments
suhail malik 2023 3-Jul-23 2:38am    
due to to blindness i can not go further in to debugging. yesterday I googled more deeply and updated my code as well as question. please have a look at updated question above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900