GroupedItemsPage: View jumps back to start when navigating back from detailpage - c#

I developed a quite popular news app for a newspaper. Unfortunately, my users reported the following problem that I can reproduce:
The App basically consists of a GroupedItemsPage and a ItemDetailPage (and several other pages, not important here). The GroupedItemsPage shows the news grouped by category. As the user scrolls to the right, he clicks on one of the items of interests, gets redirected to the ItemDetailPage and navigates back. Back on the GroupedItemsPage the view jumps back to the first group and does not stay at the last position (group) the user has been. The exact same behaviour can be found (in my environment) when I create a new Windows Store "Grid App".
Unfortunately, I was not able to resolve this problem on my own, nor have I found some useful comments in the web. I saw several other apps who could solve this issue and others didn't. Any comment would be very much appreciated. Thank you!

You need to implement this by your self. When navigating from GroupedItemsPage to ItemDetailPage you need to remember the click item. Then, when you navigate back to GroupedItemsPage you need to scroll to the remembered item. You can do it by using the ScrollIntoView method on your GridView.

I found another, easier solution. I'd like to share it:
In the GroupedItemsPage (XAML) i added:
<common:LayoutAwarePage
NavigationCacheMode="Enabled" ...

Related

Xamarin.Forms Swipe to change between CollectionViews

Hi there:) So that's my problem:
I've got two CollectionViews in my app and I want to be able to change between them by swiping side to side. Is there a good way to implement this?
Thanks in advance:)
At first, you can try to put the two CollectionViews in two Contentpages and set the two pages as the TabbedPage's child page. Then you can try to select different ColectionView by selecting different page when user swipes on the screen. For more information, you can check the official document about the TabbedPage.
In addition, I suggest you use the Community Toolkit's control named TabView, because it can put the two CollectionViews in the same page and there is a sample on the github, you can refer to it.

Lost DataContext when navigating back in Frame (SplitView) in UWP

I'm writing an Universal App in C# for Windows 10 using the SplitView with a frame for navigation.
I have a sidebar with a list that I load dynamically and, when I click on one of the items, I navigate to a page using the model from the menu to indicate which item I should load in the Frame.
I followed this sample: Windows-universal-samples/Samples/XamlNavigation/
The only difference is, instead of having multiple pages, I have only one page that is loaded every time I select a different item with its specific ViewModel. I use Autofac to load the ViewModels and MyFrame.Navigate(typeof(DetailsPage), idOfItem);to load the page.
The problem is, every time I navigate to the next page, it seems that the instance of the previous one is lost and when I navigate back, it loads a new instance. This kind of thing doesn't seem to happen when I'm navigating in the RootFrame and it didn't happen in Windows Phone 8.1.
I've been searching for a solution on the Web for hours, but I can't find anything relevant.
Does anyone know why this could be happening?
I hope I was clear enough with my question.
Thank you in advance for the answer.
The behavior you observe is correct and as expected. You have two options:
You can use Page.NavigationCacheMode, set it to Required. This is easy, but may consume a lot of memory.
Or you can save page state in OnNavigatedFrom and restore it in OnNavigatedTo. In fact, depending on your scenario, it may not even be necessary to save state in OnNavigatedFrom, assuming the state (your DataContext) can be constructed when returning to the page in the same way that you constructed it when first comming to the page.

windows phone skipping frames in navigation

I have an app where you could go through in views like;
play -> normal or custom -> select map -> summary -> start
I would like to make a shortcut option from play to summary, but I also want navigation back to select map page with the back button functionality.
So the normal workflow p->noc->sm->summary but I want to implement p->sm with the noc<-sm<-summary back functionality too (with the windows phone back button).
I saw how can I delete items from the backstack, but google not helped me how can I navigate through a couple of windows without showing that to the user.
Am I need to override the back button or there is a "better" way to do that?
It's a WP8 project.
Edit:
I didnt need the exact codesnippet for this just a design concept in this patform. (just for the is it duplicated guy)
My normal or custom and select map page should be randomized when I do the shortcut, both of these pages has a "button" which can randomize those settings, I just want a swipe->press->swipe->press->swipe actions shortened to a button press without loosing the 'post modification after randomized' feature.
After I read your comments I think I will handle the back button all of the mentioned views so the backstack will not be getting inconsistent at any state. If I understand well I can tell it in every page what is the "backed" page.
You can't inject pages into the backstack. You can override the back button and do a forward navigation with the animations you would normally do when going backward (and then remove the page you just came from off the stack), but honestly, this all gets complicated and for good reason. One of the few hard truths of Windows Phone design is that you shouldn't mess with the backstack.
Instead, I would rethink your flow. It seems like your second page is a setting of some sort (Normal or Custom). If that is changeable, maybe make a button that can float a modal popup on top of the page and move things around according to the new decision.
Looking again at your flow, it seems like several of the pages may be settings. Can you combine those into one page, maybe on a pivot or panorama? That way making changes is just a swipe away.
Regardless, while it is possible to do what you are looking to achieve, I would look long and hard at whether it is actually the best experience for your users.

How to call nested views in monotouch?

For example the twitter application you can open one profile and see his tweets then open another profile and go and repeat the same action over and over again, then you can tap on the back button as many times you opened tweets and profiles etc, returning from the same path.
a code example would help me a lot :)
You are looking for examples of a UINavigationController. This allows you to push new UIViewControllers into the navigation hierarchy and helps manage popping the view controllers off when you hit the back button (you can do this programatically also).
There are a bunch of articles on MonoTouch.Info about UINavigationControllers. I think that would be the best starting point for you.

List of buttons?

I've been working on a small program which gets a list of url's from the web server ( latest forum topics ) and warns the user whenever a new topic is created.
So the main form of my program have a list of buttons. Each button has the text of the forum topic and extra information below. Opens the browser with the topics url when user presses.
The problem is, creating buttons for every topic doesn't feel right. I'm sure there is a better way to create a user interface for this program. I tried listview but I need space for some extra information so one line and one text-size isn't good for it.
edit: I'm sorry, it's a windows form app.
Try ObjectListView. Here's what can be done with it:
(source: sourceforge.net)
For this sort of thing I would look at WPF and style my own controls.
You can loop through them and add the buttons and labels programmatically. Placing them vertically below eachother is simple math.
Probably not best practice, but it has always worked for me.

Categories