Apologise if there is answer for this somewhere else, I can't find any.
I imagine this is a common situation. The first time the user runs the application I want them to be presented with the SignIn.xaml, if they don't have any saved details, else I just want to go straight to the MainPage.xaml.
I'd usually do this by sticking a check in the constructor of the MainPage and if they don't have details navigate away. The problem I have is that
NavigationService.Navigate(new Uri("/SignIn.xaml", UriKind.Relative));
is coming up as a null reference. What am I missing? Is there a proper way to do something like this in WP7?
Thanks
Unfortunately the WP7 navigation framework doesn't handle the "do something on first run" situation very nicely at all.
I suspect the problem you're seeing is that you don't have a NavigationService yet... but even if you did, you'd have a problem: the user could still hit the "back" button. You can't even work around that, because the user pressing back should exit the app... but there's no way I'm aware of for doing that without already being at the first page naturally when the user hits the back button.
The only workaround I've found for this is to have the "sign-in" view in the same page as the normal first page, and display one or the other conditionally. Yes, it sucks... but it's the only approach I've found which works. If you find another, I'll be happy to hear about it :)
Peter Torr covers page redirections quite well here. Two methods are offered with relative merits covered. Edit: Note you can redirect to a login page, rather then employing the popup suggestion for login handling.
Redirecting an initial navigation - Peter Torr's Blog
I'd also recommend familiarising with his accompanying post on places here.
Introducing the concept of “Places” - Peter Torr's Blog
This address back stack handling (certification consideration) and addresses scenarios such as login pages.
Rather than have your main page navigate to a sign in page (which will upset you back stack). Either conditionally set the first page or have the login appear as a popup.
Have a look at this question for more on the subject.
I was able to get Peter Torr's UriMapper approach to work with the separate login / welcome page. The main thing was changing the Uri of the UriMapper again after the login and then changing the query string when navigating back to MainPage.xaml after finishing with the login / welcome page. Otherwise when attempting to navigate to MainPage.xaml from the login page, nothing happened.
For more info and a sample project see http://www.geoffhudik.com/tech/2012/2/19/windows-phone-login-navigation.html. I welcome any thoughts and better suggestions.
Related
I have a contact addition form that can be navigated to from multiple screens in our application.
Once the form is submitted, I then take the user to a screen to view the contact that was added.
When the user then makes use of the back button it should take them back to the screen that they originated from.
This might be the Android back button or one that calls the RouterExtensions back function.
I have made use of the navigate extra replaceUrl when navigating away from the form to the view page.
I have also tried using the skipLocationChange extra when navigating to the form but this creates more issues.
I have created a simple playground page flow that creates not quite the same issue but does throw an error that I don't know what to do with either:
https://play.nativescript.org/?template=play-ng&id=BfVcGZ&v=2
In our app, by making use of the replaceUrl extra, the back button does take the user to the correct page.
However, there is a brief moment where they see the form again. This isn't an ideal user experience.
In the linked Playground I do get an error:
Cannot reattach ActivatedRouteSnapshot created from a different route.
This seems to tell me that replaceUrl is indeed removing the page from the route table.
However, the page isn't destroyed yet and so the app is trying to show a page that it shouldn't.
replaceUrl is not yet supported by Page Router Outlet, there is an open feature request, you might want to register your vote on the feature and follow up there for further updates.
Into an Universal windows app I want to check user's authentication during page load, or after that an user as navigated to. This permits me to offer a navigation filtered by authorizations with a single page granularity.
For example, if an user didn't login and a page requires authentication, user has to be redirected to a login page.
The problem comes when I try navigate to an other page from the OnNavigatedTo event, when previous navigation is not completed and the new fails. I've searched for other events like an OnNavigationCompleted, but I don't find anything. If I use an asynchronous method without waiting it works, as if I use a timer dispatcher, but both solutions doesn't sound like so clean.
Exists a method to handle an event raised after navigation completed or I have to pre-check authorization during navigation call? I hope to avoid this solution because a wrong call could show an unauthorized page.
If you really want a separate page according to this answer https://stackoverflow.com/a/19527979/4788286 you could probably use the loaded event. But I'd test it before just to make sure.
Sidenote: also, your question implies that you're doing business logic in the view codebehinds - this is bad practice, I suggest looking into the MVVM pattern. (If you need a framework I suggest MVVMLight or PRISM)
I think the precheck would be the best method. Check if they are authorized to view the page before they can navigate to the page. If they are not authorized ask if they want to log in or purchase rights to the page
I am making an app for FB to be able to ban people from my facebook page even when they have not yet commented or liked my page. Just like detailed here. I have a browser written in Lazarus, it logs onto facebook, navigates to page/settings, selects the first user on the "People who like this" list and changes the url and gives me a confirm dialog:
The below code creates this dialog:
<a class="_54nc" href="/pages/likes/label_fans/?action=remove&page_id=1234567890&user_id=1234567890" rel="async-post" role="menuitem"><span><span class="_54nh">Remove</span></span></a>
I would like to parse the popup dialog when it hits OnDocumentComplete event, but I am not able "catch" it. (I guess it is due to the fact this is made with AJAX(?) and with "async-post". )
Anyone knows why?
Thanks in advance,
modzsi
It looks like you can do it via API:
https://developers.facebook.com/docs/graph-api/reference/v2.0/app/banned
It doesn't mention any restriction to the user id's you can pass in.
I guess you'll need another API call to retrieve the list of people "Who Like This".
I am trying solve the back button issue within my app. The scenario is:
I have a home page with a search form which sends and receives data with $.ajax(), then the results loaded through ajax, their links points to a controller that won't be done by GET in ajax so that means that the page will be refreshed (so the home page with the results looks like this: http://url/en/home and a result link may look like this http://url/fetch/data/x123av).
The problem is which is the best way fix that when click back button to return the results from the search box?
I have found some answers in stackoverflow related to my question:
http://code.google.com/p/reallysimplehistory
http://tkyk.github.com/jquery-history-plugin
But from the documentation of those plugins, they all work by checking the hash change which I don't have.
Hope I have explained well enough, and I do have searched stackoverflow and google for a solution but I didn't find one that is close to this or either I've jumped over it...
Please just point me to the right way :D
But from the documentation of those plugins, they all work by checking
the hash change which I don't have.
If you want to handle the back button with AJAX request you will have to redesign your application so that it works with hashes as that's the only way. Changing the fragment portion of an url doesn't trigger a page reload but it is added to the history, so when you press the back button you are able to detect this change without navigating away from the page.
As mentioned by SLaks in the comments section another possibility is to use the HTML5 history API but obviously this assumes that the client browser supports it.
Long story short;
I have facebook Like-button on my website with comment box enabled.
I need to refresh current page every time user clicks like button (likes or unlikes my content).
I can achieve this with event.subscribe and edge.create / edge.remove events but the problem is that user should be able to post comments with like-clicks, too.
Currently this works fine with like-clicks only but the edge.create / edge.remove event executes in a few seconds after user has clicked like button and therefor not giving user enough time to write her comment in the comments box and post it.
I've tried comment.create and comment.remove events, but they're not firing at all when the comment is posted and because of that the page just won't refresh at all.
So the problem is;
Does anyone know how I can execute page refresh when user posts comment with like-click via the comment box that is integrated with like-button?
Any help would be appreciated! Thanks!
After struggling with this same problem for a while, and not being able to find a solution, I decided to go another approach.
While I see value in the Comments Box, I also see it as not very good design to have a Comments Box appear seconds before the page redirects/refreshes. So... with a little CSS you can hide the Comments Box, which might be a good option for you until Facebook makes Subscribing to a Like Comment Post, or Close of the Comments Box.
.fb_edge_comment_widget {
display: none !important;
}