How to check if Image is loaded while coming back in Navigation stack - windows-phone-7

In my MainPage I have added many images, each of them is retrieved from server by making HttpWebRequest. Also there are some links on MainPage, clicking on those links takes the user to a new page.
The problem I am facing is before all the images are loaded in the MainPage itself, if I click on any of the links on the MainPage, a new page is created and shown and all the pending image requests are canceled. Now If I come back to MainPage by clicking on the back button, the unloaded images still remain unloaded.
I have no idea how to check whether the images have already been loaded or not, when I come back to MainPage in the navigation stack(If I am able to find out that some images are not loaded, I can request the server again for the unloaded images). I need a generic solution for this. Because parent child relationship in the MainPage content layout is dynamic, means I do not know the hierarchy of the Image control, Image control can be a child of a canvas which in turn added to the MainPage's Content grid or the image can be added in one of the sections of a panorama/pivot which in turn added to the MainPage's Content grid, etc,....

There is an event on the Image control related to that -> http://msdn.microsoft.com/en-us/library/system.windows.controls.image.imageopened(v=vs.95).aspx

As argh suggested use the ImageOpened event (and perhaps also ImageFailed) to track whether the image has been loaded successfully. You could create a wrapper control around Image (can't inherit since it is sealed) to monitor the event and implement your own IsLoaded property.
You can use VisualTreeHelper.GetParent to traverse up through the tree and see whether the Image control is a descendant from MainPage for the second part of your problem.
This should work, however, I'm wondering why the images are not re-loaded when you press the back button. I don't think any of the suggested 'hacks' should be necessary. Are you using any custom logic for image loading etc.?

You can check Name of Image Temp . beacause in my project i use image temp show before image has load in server.
You can check the current name of the Image, if it is similar to the Temp Image name, then continue down they will not down
My code :
if(((BitmapImage)img.Source).UriSource.Equals("/NhomMua;component/Image/img_temp_sale.png"))
{
//code of you
}

I would suggest you have a look at the LowProfileImageLoader http://blogs.msdn.com/b/delay/archive/2010/09/02/keep-a-low-profile-lowprofileimageloader-helps-the-windows-phone-7-ui-thread-stay-responsive-by-loading-images-in-the-background.aspx) as a generic way to handle loading of images in an efficient manner. If you specifically need to be able to cancel and resume the loading of images you should able to modify that code to handle that pretty easily - although I'm not sure why you'd want to, remember its more efficient on the battery to download all the images in one hit than to stop and start.

Related

In Flutter, how to create an UI like Uber to have map in middle and AppBar and navigate to different type of views

I am pretty new to Flutter. I am working on a project to create an UI like Uber to have google map in the background and have different type of views, such as full screen address input view(it seems full screen but part of the view can be hidden to expose the map behind and interact with it), persistent bottom sheets and some floating button on top. Using stack to put one bottom sheet on the map is not difficult. But when it comes to navigate back and forth between different type of views while keeping the map in the background and the map is still touchable, I am not sure how to manage it. Sometimes it navigate 2-3 times deep and back to the first bottom sheet. So the question is:
How to implement a way to navigate between different type of views, like firstly pull up full screen address view, pop the address view after entering address and pull up car type view as the sample image shown on the link below. And press on the back button on top left corner will go back to address view.
If you have any idea how to design this navigation flow, please share it. Thank you.
Sample image
Update: found this GitHub repository demonstrating how to implement Uber like UI. I am checking it out.
https://github.com/iamSahdeep/fu_uber
For background maps with elements on top, a Stack is best as you mentioned.
For persistent bottom sheets, use the BottomSheet class
For the floating button, use the FloatingActionButton class
For the navigation between BottomSheets only, you might want to learn more about this plugin Modal Bottom Sheet. It has exactly what you need. Check the "Cupertino Modal with inside Navigation".

Animating page navigation in WP 8.1 while the current page stays still

In WP 8.1 Store app, how can I change page animation upon navigating to another page within the frame such that the current page stays still while the new page is animating on top of it by moving from the top of the screen to the bottom?
I'm currently animating my navigation like so:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Frame.ContentTransitions = new TransitionCollection
{
new PaneThemeTransition{Edge = EdgeTransitionLocation.Top}
};
}
But this is animating both pages by moving the current one from bottom to top while the second one simultaneously moves from top to bottom. I'm also seeing a black background while the pages are moving for screen area that's not occupied by any content.
You unfortunately can not navigate to a different page and keep the previous page visible during the animation. That is why all page Transitions right now only support an In-Transition and an Out-Transition. We discussed the issue with Microsoft developers during this years //Build so I'm certain of this information.
If you really need that effect you can perhaps achieve it using a workaround. Instead of placing your content on separate pages you would create user controls and animate those while staying on a single page. This however can be a little tricky due to you manually having to manage "navigation" between the user controls instead of having the system deal with it for regular pages.
More information on how to implement animations in Windows Phone Silverlight Apps can be found in this article: http://msdn.microsoft.com/en-us/library/windows/apps/jj206955%28v=vs.105%29.aspx
I had a similar problem a while ago and it is kind of a workaround as well but it might do the trick for you.
You can place a Frame object taking all the available space on your current page. Then, instead of navigating from your current Page Frame, you navigate from the Frame object you put on top of your actual page.
The problem with this approach is that you would really "get rid" of the first page.
But this can work for you, or at least give you another insight of the problem.

WebBrowserControl uninitialized when coming back from sub screen

i have a page with a WebBrowserControl + some buttons at the bottom. When i click on of the buttons, a subpage is opened (NavigationService.Navigate(...)).
Now, when i'm on the sub page and close that page via NavigationService.GoBack() the WebBrowserControl is just white. Seems like it is completely uninitialized. Also checking WebBrowserControl.Sourcegives null.
Any ideas?
In a case like this you would want to make sure you are keeping track of objects in isolated storage or known as TombStoning on the WP7.
you would want to save page state onNavigatingFrom() and Load it onNavigationTo().
That should work. :)

Updating a single image of an IKImageBrowserView

I searched everywhere and can't seem to find a way to do this.
I am currently making a simple application to help our user configure image metadata for another application.
I present the list of image to be configured in an IKImageBrowserView. The user selects an image. which is then displayed in another view and adds stuff to it.
I'd like to be able to update the IKImageBrowserView thumbnail "live", as the user manipulates the image. I am able to take a "screenshot" of the view on which he is working but can't for the life of me find a way to update this single IKImageBrowserView item without having to call reloadData.
Is there a way to update a single image in an IKImageBrowserView without calling reloadData?
Thanks!
Look at the -imageVersion method. This will cause the cache for that item to be invalidated. There also appears to be a private -reloadCellDataAtIndex: method that might be of interest. Updating the image's version and calling -reloadData should be sufficient though.

Which is better, some grids collapsed or some user controls?

I'm developing a Windows Phone 7 application that uses some Transient content.
To avoid to go back to that transient content I've decided to use a phew page with several grids on the same page.
When I have to show another "page" I set to collapsed current grid and then I set to visible desired grid.
I know this can be done using user control, but I'm not sure if using user controls can be slowest that using Grids. Any advice?
And another question is if I use grids, how can I use page transitions?
Another option for when you want to show transient content is to use a Popup control. This won't appear in the navigation stack, so when a user goes back (<-) they won't see this content.
However, Popup content isnt GPU accelerated, so you only want to display simple content, no animations etc...
If you want page transitions etc... then i think your only option is to use Pages. That way you can do the transitions and the back button works as expected.
It doesn't matter if you do this via user controls or grids - what matters speed wise is the complexity of your layout.
A user control may be better if you are doing this on a number of pages so you don't repeat yourself.
One way to do page transitions is to do it with stack panels. Have the second "hidden" stack panel way off to the right so it is off screen then animate it in.

Resources